Bird
0
0

What is wrong with this Flask test code snippet for login?

medium📝 Debug Q6 of 15
Flask - Testing Flask Applications
What is wrong with this Flask test code snippet for login?
response = client.post('/login', json={'username': 'user', 'password': 'pass'})
ANot setting headers for content type
BMissing follow_redirects=True parameter
CIncorrect URL endpoint for login
DUsing 'json' instead of 'data' for form submission
Step-by-Step Solution
Solution:
  1. Step 1: Understand form submission

    Flask login routes usually expect form-encoded data, not JSON.
  2. Step 2: Identify parameter usage

    Using 'json' sends JSON payload, which may not be handled by the login route.
  3. Final Answer:

    Using 'json' instead of 'data' for form submission -> Option D
  4. Quick Check:

    Use 'data' for form data, not 'json' [OK]
Quick Trick: Form data requires 'data', not 'json' [OK]
Common Mistakes:
MISTAKES
  • Confusing JSON payload with form data
  • Assuming login accepts JSON by default
  • Ignoring content type expectations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes