Complete the code to create a test client for the Flask app.
with app.[1]() as client: response = client.get('/')
The test_client() method creates a client to simulate requests to the Flask app for testing.
Complete the code to check the HTTP status code of the response.
assert response.[1] == 200
The status_code attribute holds the HTTP status code returned by the response.
Fix the error in the test by completing the code to decode the response data.
assert response.data.[1]('utf-8') == 'Hello, World!'
The response data is bytes, so we decode it to a string using decode('utf-8').
Fill both blanks to test a POST request with JSON data and check the response JSON.
response = client.post('/submit', json=[1]) assert response.[2]['status'] == 'success'
We send JSON data as a dictionary in the json parameter. The response JSON is accessed via response.json.
Fill all three blanks to test a route with query parameters and check the response text.
response = client.get('/search?query=[1]') assert response.[2] == 200 assert response.data.[3]('utf-8') == 'Results for test'
The query parameter is 'test'. We check status_code for 200. The response data is decoded with decode('utf-8') to compare text.