svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 325 forks source link

extract_binds always return unicode string #249

Closed JohnnyWuMigme closed 7 years ago

JohnnyWuMigme commented 7 years ago

I encounter a similar problem as below: https://github.com/svanoort/pyresttest/issues/77

Here is my test:


So I was trying to save the session id from 1st login test and use it in 2nd test. When I run debug mode, I see this:


> ./resttest.py --print-bodies=True --log=DEBUG --interactive=True http://localhost:8080 PROD.yaml 
> ...
> ...
> INFO:Test Succeeded: login URL=http://localhost:8080/api/v1/users/login Group=PROD
> 
> Add Following
> -----------------------------------
> REQUEST:
> POST http://localhost:8080/ap/v1/users/12345/followings
> HEADERS:
> {'sessionId': u'qJ9jv57c7PetwW9CdEiA0bVJR2siMCSR70TgDSwlaiU7wpSEKW2YxSaKunLhY5JLfd4+Yn4JfEZ7yxNFx6hQWQFUYyy//QTdIwk6bD0oGqa56MFTjz3elbT4YL5zci9M7I6dv02zL/WIIW9R4b1nG9cC5xTWiPW0bFFN9Rc5a6iuiA6kWKuKIJDqSSeLRKc1j/e8rovC+FeUVYjG572zbdwxrp+NpFa3oaNJUM4Fw6U='}
> 
> {"followings": ["123", "1234"]}
> Press ENTER when ready (0): 
> 
> 

The sessionId returns with unicode string and that makes 2nd test failed with code 415 Bad Request.

I notice in issue 77, you mentioned the simplest way to avoid this is:

Simplest: just extract simple fields (not full structures) and use them in a template like so: https://github.com/svanoort/pyresttest/blob/master/pyresttest/content-test.yaml#L46

However, here is the response of my login API:

{"sessionId":"/CDj6sJvdd9Mio1egUTdmrEVz9uKowWCsXsDEvaAXvFcxvrZgXn2XYFuN6ExXXNsvGbOfOi9OiYRNQSKZIC60cqDEki3P5pB5RQN+NAe00XTQX6lqXMM6BO+kGZzZW+7KnzzoHBec390iTOTBZlS76faw3xpdDFxh7W+o10Wp01YgIgGeKM2ZvXA5MpCdi7cB6b2OCqgGFtFgoTGe112bVyRSmd0pOpU1PP7J8Fv24Y=","captcha":null,"message":null}

It is the only structure I can extract from.

Do we have any workaround here? To extract the correct pure string of session id from json response?

Thanks for your kindly reply!!

Regards, Johnny

JohnnyWuMigme commented 7 years ago

Sorry... my login data had problem. The unicode session id is fine, will not affect usage. Sorry for bothering.