Bird
0
0

What is wrong with this test code?

medium📝 Debug Q7 of 15
Rest API - API Testing and Monitoring
What is wrong with this test code?
response = client.post('/orders', data={'id': 10})
assert response.status_code == 201
assert response.json()['id'] == 10
AIncorrect status code for POST request
BUsing 'data' instead of 'json' for JSON payload
CMissing assertion for response content type
DNo error, test is valid
Step-by-Step Solution
Solution:
  1. Step 1: Check payload format for JSON POST

    Use 'json' parameter to send JSON, not 'data' which sends form data.
  2. Step 2: Confirm status code and assertions

    Status code 201 is correct for creation; assertion on id is valid.
  3. Final Answer:

    Using 'data' instead of 'json' for JSON payload -> Option B
  4. Quick Check:

    Send JSON with 'json' parameter, not 'data' [OK]
Quick Trick: Use json= for JSON body in POST requests [OK]
Common Mistakes:
MISTAKES
  • Sending JSON with 'data' instead of 'json'
  • Assuming 200 is correct for resource creation
  • Not checking response content type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes