Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a GET request using the requests library.
Testing Fundamentals
response = requests.[1]('https://api.example.com/data')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET when only retrieving data.
Using PUT or DELETE which modify data.
✗ Incorrect
The get method sends a GET request to the specified URL.
2fill in blank
mediumComplete the code to check if the response status code is 200 (OK).
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 which means Not Found.
Using 500 which means server error.
✗ Incorrect
Status code 200 means the request was successful.
3fill in blank
hardFix the error in the code to parse JSON response correctly.
Testing Fundamentals
data = response.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
text which returns raw string.Using
content which returns bytes.✗ Incorrect
The json() method parses the response body as JSON.
4fill in blank
hardFill both blanks to send a POST request with JSON data.
Testing Fundamentals
response = requests.[1]('https://api.example.com/create', json=[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for sending data.
Passing JSON as a string instead of a dictionary.
✗ Incorrect
Use post to send data and pass JSON as a dictionary.
5fill in blank
hardFill all three blanks to assert the response contains expected data.
Testing Fundamentals
assert [1] in response.json() and response.json()[[2]] == [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for wrong keys or values.
Not verifying key existence before value.
✗ Incorrect
Check that the key 'status' exists and its value is 'active'.