How can i get header from request and set it to pytest environment? - python-3.x

I was set for task to write small autotest API. (even though I am a manual junior tester).
The function is:
def test_post_tokens
In this post request I need to get authrization-header from response.
Next I need to pick up this token and insert it into other requests. (or set it to pytest environment). For example:
def test_get_account_info
It is possible to manually set a token for each request, but it takes a lot of time and the hunt to do everything correctly.
In postman, I solved this problem by getting a token in the first request and setting it in an environment
pm.environment.set ("token", postman.getResponseHeader ("Auth-Token"));

Related

how to extract token generated by js script (challenge.flood.io)

I am currently studying Gatling for performance testing, I am new to both. Making the task, I have stuck on the step when I need to get a token to pass it to parameter to get to the other page.
The difficulty for me is that the token is absent in the body, it is generated by a script, so I cannot get it with ...check(css(... or check(regex(...
I tryed to get the token by css and regex, getting empty result
.exec(
http("Step 5 page")
.get("${redirection}")
.check(status.is(200))
.check(substring("Step 5"))
.check(css("input[name='challenger[step_id]']", "value").find.saveAs("step_id"))
.check(css("input[name='challenger[step_number]']", "value").find.saveAs("step_number"))
.check(css("input[name='commit']", "value").find.saveAs("commit"))
.check(css("span.token").find.saveAs("one_time_token")))
How can I get the token?
It's pretty clear from this code that this page is performing an extra ajax request to the /code url to fetch the token and then display it in the page.
You'll find the value in there (you can see this HTTP request a few lines below in the Network tab).
Note: in order to learn Gatling you should probably check the Gatling Academy.

How to configure or set cookie as json before making a post request in locust load test tool for FastHTTPUser

Locust is having option to use HTTPUser and FastHTTPUser
HTTPUSer internally using python requests which accepts cookies as an argument with json content
e.g. self.client.get(url, header=myheader, cookies=mycookies) here I can configure mycookies as json. Same is not working if I change the code to FastHTTPUser instead of HTTPUser. Need details how to configure hardcoded cookies as key value before making the request in FastHTTPUser approach.
I don't see why you have received downvotes for your question. I found it valid and I think you should create an issue in the locust github page:
https://github.com/locustio/locust/issues/
I think you could solve it like this:
from requests.cookies import cookiejar_from_dict
#task
def task_cookie(self):
cookiejar_from_dict(mycookies, self.client.cookiejar)
self.client.get(url, header=myheader)
I will try to make a PR to make this automatic

Multiple api call

I'm trying to build a nodejs app that runs and if statement to query multiple api's to return a result. Example, running yelps api first, if it finds then break, else continue query another api such as google places or white pages api until it finds a result.
I am passing in either a name of a business, address to return a telephone number. the results expected are in json. I am drawing a blank.
ideas?
so the way to achieve this is you should be able to make http req from your server side and when a result comes with a response then you should check that response. If your requested answer is not in it then you should keep on trying other API end points untill u come across with a suitable response..
so here are some npm packages to achieve this simply
http - node js built in package
Axios - here
request - here
try using one of these packages .. I would use axios .. read their doc and try to do it .. It should clear somethings out for you

Unicode-objects must be encoded before hashing when requesting data using Flask-OAuth

I'm integrating Google's login with a Flask site using Flask-OAuth.
Everything is working fine. I can authorise the login and get a token back etc without any difficulties. But when I use Flask-OAuth's get method to request the logged in user's email address I get an error saying:
TypeError: Unicode-objects must be encoded before hashing
I'm using Python3 and this has the smell of a Python version issue but I can't figure out what I'd need to change.
The code I'm using is this:
def get_additional_data(self):
access_token = session.get('oauth_token')
headers = {'Authorization': 'OAuth ' + access_token[0]}
return self.service.get(
'https://www.googleapis.com/oauth2/v1/userinfo', None,
headers=headers)
I'm not sure what I can encode in that request. Even if I don't pass the headers I get the same error (rather than an invalid request or something like that).
I've run 2to3 on oauth2/__init__.py and the tweaks is suggests are very minor and shouldn't prevent the code from running in Python 3. Also, everything else OAuth2 related is working.
The bad news is that the solution to this problem is switching to Flask-OAuthlib.
The good news is it required very few changes from Flask-OAuth to get it working.

How to send POST variables with Nipple on NodeJS

I am trying to use nipple to post to an url within my nodejs application, which itself is running on hapi.js
The documentation essentially doesn't seem to spell it out.
(https://www.npmjs.com/package/nipple)
I tried passing it as payload inside options but that, while not returning an error, returns a 400. Can someone provide a correct example doing a post using nipple?
Essentially, I have two variables that I need to send - let's call the var1 and var2.
Thanks!
That link says that the project has been renamed to wreck. On wreck's github, several of the tests are for a post requests, including this one:
https://github.com/hapijs/wreck/blob/master/test/index.js#L68
If you are still scratching your head, you could also try using curl or postman to sanity check your URL, regardless of any nipple/wreck errors. If that also gives you a 400, nipple/wreck may not be the culprit.

Resources