Bird
0
0

How can you test a Flask route that requires a custom header X-Auth-Token in the request?

hard📝 Application Q9 of 15
Flask - Testing Flask Applications
How can you test a Flask route that requires a custom header X-Auth-Token in the request?
Aclient.get('/secure', cookies={'X-Auth-Token': 'abc123'})
Bclient.get('/secure', auth_token='abc123')
Cclient.get('/secure', headers={'X-Auth-Token': 'abc123'})
Dclient.get('/secure', data={'X-Auth-Token': 'abc123'})
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to send headers in test client

    Headers are passed as a dictionary to the headers parameter in client.get() or client.post().
  2. Step 2: Identify correct usage for custom header

    client.get('/secure', headers={'X-Auth-Token': 'abc123'}) correctly passes the custom header 'X-Auth-Token' in headers.
  3. Final Answer:

    client.get('/secure', headers={'X-Auth-Token': 'abc123'}) -> Option C
  4. Quick Check:

    Send headers via headers parameter [OK]
Quick Trick: Use headers={'Header-Name': 'value'} to send headers [OK]
Common Mistakes:
MISTAKES
  • Passing headers as data or cookies
  • Using wrong parameter names like auth_token
  • Not including headers dictionary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes