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' for retrieving data.
✗ Incorrect
The get method sends a GET request to retrieve data from the API.
2fill in blank
mediumComplete the code to check if the response status code is 200 (OK).
Testing Fundamentals
assert response.[1] == 200
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking response.text instead of response.status_code.
✗ Incorrect
The status_code attribute holds the HTTP status code returned by the API.
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 response.text instead of response.json() to parse JSON.
✗ Incorrect
The json() method parses the response body as JSON and returns a dictionary.
4fill in blank
hardFill both blanks to send a POST request with JSON payload and check status code.
Testing Fundamentals
response = requests.[1]('https://api.example.com/create', json=[2]) assert response.status_code == 201
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET method instead of POST.
Passing payload as string instead of dictionary.
✗ Incorrect
Use post to send data and provide the JSON payload as a dictionary.
5fill in blank
hardFill all three blanks to extract a value from JSON response and assert it equals expected.
Testing Fundamentals
data = response.[1]() value = data.get('[2]') assert value [3] 'success'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.text instead of response.json().
Wrong key name in get().
Using assignment '=' instead of comparison '=='.
✗ Incorrect
Parse JSON with json(), get the 'status' key, and assert it equals 'success'.