Complete the code to define a contract test that checks the response status code.
def test_api_response(): response = client.get('/api/data') assert response.status_code == [1]
The expected status code for a successful API response is 200.
Complete the code to check that the response content type is JSON.
def test_content_type(): response = client.get('/api/data') assert response.headers['Content-Type'] == [1]
The API should return data in JSON format, so the content type must be application/json.
Fix the error in the contract test that verifies the JSON response has a 'name' field.
def test_response_has_name(): response = client.get('/api/user') data = response.json() assert [1] in data
The contract requires the JSON response to include the 'name' field.
Fill both blanks to create a contract test that verifies the 'age' field is an integer and greater than 18.
def test_age_field(): response = client.get('/api/user') data = response.json() assert isinstance(data['age'], [1]) and data['age'] [2] 18
str instead of int< instead of >The 'age' field must be an integer and greater than 18 to meet the contract.
Fill all three blanks to write a contract test that filters users with 'active' status and checks their 'email' contains '@'.
def test_active_users_email(): response = client.get('/api/users') users = response.json() active_users = [user[1] user in users if user['status'] [2] 'active'] assert all('[3]' in user['email'] for user in active_users)
The list comprehension uses for to iterate, == to check status, and '@' to verify emails.