0
0
Flaskframework~10 mins

Testing authentication flows in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ATestClient
BFlaskClient
CClient
DTestCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'TestClient' which is not the correct Flask class.
Importing 'TestCase' instead of the client.
2fill in blank
medium

Complete 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'
Atest_client
Bcreate_client
Cclient
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create_client' which is not a Flask method.
Using 'client' which is just a variable name.
3fill in blank
hard

Fix 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'
A'username=user&password=pass'
B['username', 'user', 'password', 'pass']
C{'username': 'user', 'password': 'pass'}
D('username', 'user', 'password', 'pass')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list or tuple instead of a dictionary.
Passing a URL-encoded string instead of a dict.
4fill in blank
hard

Fill 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'
A'Welcome, user!'
B200
C404
D'Login failed'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'Login failed' instead of the welcome message.
Using status code 404 which means not found.
5fill in blank
hard

Fill 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'
ATrue
B302
C'Login Page'
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting follow_redirects to False and missing the redirect.
Checking for wrong status codes or page content.