qxf2 / cars-api

A sample REST application to help testers learn to write API automation
MIT License
6 stars 20 forks source link

Add decorator for different response #9

Open Annapooraniqxf2 opened 4 years ago

Annapooraniqxf2 commented 4 years ago

We wanted to show the different api responses to our trainee. So we have added the decorator which returns different responses for a same request. We are randomly generating different responses for each request. We are trying to change the headers, values and status code.

Added file: utils/spoiler.py

Changed files: cars_app.py We have added the decorator as of now for the /cars route method only.

How do we test it:

  1. Open the bash and run the server "python cars_App.py"
  2. Open the Python interpreter and import the requests
  3. Run requests.get("http://localhost:5000/cars", auth=("qxf2", "qxf2"))
  4. Everytime you run it gives the different responses.
Annapooraniqxf2 commented 4 years ago

Please review this pull request before 25-Aug-2020.

avinash010 commented 4 years ago

Annapoorani, I can do this next Monday

On Tue, Aug 18, 2020 at 1:39 PM Annapooraniqxf2 notifications@github.com wrote:

Please review this pull request before 25-Aug-2020.

— You are receiving this because your review was requested. Reply to this email directly, view it on GitHub https://github.com/qxf2/cars-api/pull/9#issuecomment-675328926, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZCGJNO7DFQIAVR7KEUVULSBIZMTANCNFSM4P6NNWTQ .

-- Avinash Shetty Qxf2 Services http://qxf2.com/ +91 9900234948 | avinash@qxf2.com

Annapooraniqxf2 commented 4 years ago

Please review this fix and let me know the suggestions. Thanks

avinash010 commented 4 years ago

Hi Annapoorani, I tested by running it multiple times, the headers and status were varying. What should the change_json_value update? I was expecting it to clear the actual response and return a Null value, which wasn't happening.

Also, I noted a small typo in spoiler.py comments. function is misspelled as funtion. "Use this decorator to vary your funtion return value"

rohanj-qxf2 commented 4 years ago

@Annapooraniqxf2 I reviewed the code today. This is what I did/see

Code Review Session

  1. Ran cars_app locally
  2. Called /cars method via postman
  3. I could see different status codes like 502,500,301 and also 200 being returned every time I executed the request but I could not see the change in headers or the JSON response 👍
  4. Changed if random.uniform(0, 1) < 0.01 to if random.uniform(0, 1) < 0.9 and i could see header value being set to Null 👍
  5. Changed if random.uniform(0, 1) < 0.1 to if random.uniform(0, 1) < 0.9 so that i can see different json response but it din't show the expected response 👎 6 . Made request with invalid username ,it returned 401 which is expected 👍

Issues/Queries

  1. I don't see json_response being returning different values
  2. Can we change method name - get_random_status to get_random_status_code to be specific and also change_headers to change_resposne_headers
  3. Any specific reason we used the name Spoiler for the utility?