Complete the code to import the pytest module for testing.
import [1]
We use pytest to write and run tests in Python. Importing it allows us to use its features.
Complete the code to send a GET request using the requests library.
response = requests.[1]('https://api.example.com/data')
To retrieve data from an API, we use the get method of the requests library.
Fix the error in the assertion to check the response status code is 200.
assert response.status_code [1] 200
We want to confirm the status code equals 200, which means success. So we use ==.
Fill both blanks to check if the JSON response contains a key 'name' and its value is not empty.
data = response.json() assert '[1]' in data and data['[2]'] != ''
We check if the key name exists and its value is not an empty string.
Fill all three blanks to create a test function that sends a GET request, checks status code 200, and asserts the response contains a 'success' key with value True.
def test_api_response(): response = requests.[1]('https://api.example.com/status') assert response.status_code [2] 200 assert response.json().get('[3]') is True
The test sends a GET request, asserts the status code equals 200, and checks that the JSON response has a 'success' key with value True.