Bird
0
0

What is wrong with this Flask test code snippet?

medium📝 Debug Q14 of 15
Flask - Testing Flask Applications
What is wrong with this Flask test code snippet?
client = app.test_client()
response = client.get('/login')
assert response.status == 200
AThe attribute should be response.status_code, not response.status.
BThe test client must be created with FlaskClient() instead.
CThe assert statement should check response.data, not status.
DThe get() method requires a POST request instead.
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct attribute for HTTP status

    Flask response objects use status_code to hold the HTTP status number, not status.
  2. Step 2: Check the assert statement

    The assert should compare response.status_code == 200 to be valid.
  3. Final Answer:

    The attribute should be response.status_code, not response.status. -> Option A
  4. Quick Check:

    Use response.status_code for HTTP status [OK]
Quick Trick: Use response.status_code, not response.status [OK]
Common Mistakes:
MISTAKES
  • Using response.status instead of response.status_code
  • Thinking get() requires POST method
  • Confusing assert target with response data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes