Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a Flask test client instance.
Flask
from flask import Flask app = Flask(__name__) test_client = app.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'test_client' without parentheses creates a reference, not an instance.
Trying to call 'get' or 'post' directly on the app instead of on the test client.
✗ Incorrect
The test_client() method creates a test client instance for the Flask app.
2fill in blank
mediumComplete the code to send a GET request to '/' using the Flask test client.
Flask
response = test_client.[1]('/')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for a GET request.
Using 'put' or 'delete' which are for other HTTP methods.
✗ Incorrect
The get method sends a GET request to the specified URL.
3fill in blank
hardFix the error in accessing the response data as text.
Flask
data = response.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' which is bytes, not string.
Using 'json' without parsing the response.
✗ Incorrect
The text attribute contains the response body as a string.
4fill in blank
hardFill both blanks to send a POST request with JSON data using the test client.
Flask
response = test_client.[1]('/submit', 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 data as a string instead of a dictionary.
✗ Incorrect
Use post method to send POST requests and pass JSON data as a dictionary.
5fill in blank
hardFill all three blanks to check the response status code and content type.
Flask
assert response.status_code == [1] assert response.headers['Content-Type'] == '[2]' assert 'text/html' in response.headers.get('[3]', '')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 status code which means not found.
Using wrong header key names or values.
✗ Incorrect
Status code 200 means success. The Content-Type header shows the response format. Checking header keys is case-sensitive.