0
0
Flaskframework~10 mins

Why testing matters in Flask - Test Your Understanding

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
app = Flask(__name__)
client = app.[1]()
Drag options to blanks, or click blank then click option'
Atest_client
Bstart
Cdebug
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' instead of 'test_client' to create the testing client.
2fill in blank
medium

Complete the code to check the response status code in a test.

Flask
response = client.get('/')
assert response.[1] == 200
Drag options to blanks, or click blank then click option'
Astatus_code
Bcontent
Ctext
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'content' or 'text' instead of 'status_code' for the response status.
3fill in blank
hard

Fix the error in the test function to use the correct Flask test client method.

Flask
def test_homepage():
    response = client.[1]('/home')
    assert response.status_code == 200
Drag options to blanks, or click blank then click option'
Apost
Bfetch
Crequest
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fetch' or 'request' which are not Flask test client methods.
4fill in blank
hard

Fill both blanks to create a test that posts JSON data and checks the response.

Flask
response = client.[1]('/submit', json=[2])
assert response.status_code == 201
Drag options to blanks, or click blank then click option'
Apost
B{'name': 'Alice'}
C{'age': 30}
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'post' for sending data.
5fill in blank
hard

Fill all three blanks to write a test that sends data, checks JSON response, and asserts a key.

Flask
response = client.[1]('/api/data', json=[2])
data = response.[3]()
assert 'result' in data
Drag options to blanks, or click blank then click option'
Apost
B{'query': 'test'}
Cget_json
Djsonify
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'jsonify' instead of 'get_json' to parse response.