Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the response status code is 200.
Testing Fundamentals
assert response.status_code == [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 instead of 200
Checking status_code as a string instead of integer
✗ Incorrect
The status code 200 means the request was successful.
2fill in blank
mediumComplete the code to verify the response JSON contains the key 'success'.
Testing Fundamentals
assert 'success' [1] response.json()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'in'
Using 'not in' which checks absence
✗ Incorrect
The 'in' keyword checks if 'success' is a key in the JSON response.
3fill in blank
hardFix the error in the assertion to check the response time is less than 500 milliseconds.
Testing Fundamentals
assert response.elapsed.total_seconds() * 1000 [1] 500
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which means greater than
Using '==' which checks equality
✗ Incorrect
The response time should be less than 500 ms, so use '<'.
4fill in blank
hardComplete the code to extract the 'data' field from the JSON response and check it is a list.
Testing Fundamentals
data = response.json()'data' assert isinstance(data, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of brackets
Checking type against 'dict' instead of 'list'
✗ Incorrect
Use square brackets to get 'data' from JSON dict, then check if it is a list.
5fill in blank
hardFill all three blanks to create a test that asserts the response JSON has a 'status' key with value 'ok'.
Testing Fundamentals
json_data = response.json() assert [1] and json_data[2] [3] 'ok'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for value check
Not checking if key exists before accessing
✗ Incorrect
Check if 'status' key exists, get its value, and assert it equals 'ok'.