Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask testing client.
Flask
from flask import Flask from flask.testing import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'TestClient' which is not the correct Flask class.
Importing 'TestCase' instead of the client.
✗ Incorrect
The Flask testing client is imported as FlaskClient from flask.testing.
2fill in blank
mediumComplete the code to create a test client from the Flask app.
Flask
app = Flask(__name__)
client = app.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create_client' which is not a Flask method.
Using 'client' which is just a variable name.
✗ Incorrect
The method to create a test client in Flask is test_client().
3fill in blank
hardFix the error in the test login POST request code.
Flask
response = client.post('/login', data=[1], follow_redirects=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list or tuple instead of a dictionary.
Passing a URL-encoded string instead of a dict.
✗ Incorrect
The data argument expects a dictionary with form keys and values.
4fill in blank
hardFill both blanks to check if the login response contains the welcome message.
Flask
assert [1] in response.data.decode('utf-8') and response.status_code == [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'Login failed' instead of the welcome message.
Using status code 404 which means not found.
✗ Incorrect
The response should contain the welcome message string and have status code 200 for success.
5fill in blank
hardFill all three blanks to test logout and verify redirection status code.
Flask
logout_response = client.get('/logout', follow_redirects=[1]) assert logout_response.status_code == [2] assert '[3]' in logout_response.data.decode('utf-8')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting follow_redirects to False and missing the redirect.
Checking for wrong status codes or page content.
✗ Incorrect
Follow redirects should be True to follow the logout redirect. The status code 302 means redirect. The login page text confirms logout success.