Bird
0
0

Which of the following is the correct way to test a GET request to the '/' route using Flask's test client?

easy📝 Syntax Q12 of 15
Flask - Testing Flask Applications
Which of the following is the correct way to test a GET request to the '/' route using Flask's test client?
Aresponse = client.post('/')
Bresponse = client.get('/')
Cresponse = client.request('PUT', '/')
Dresponse = client.fetch('/')
Step-by-Step Solution
Solution:
  1. Step 1: Identify the HTTP method for the route

    The question asks for a GET request, so the method should be get().
  2. Step 2: Match the method with the test client syntax

    Flask test client uses client.get(path) to send GET requests. Other methods like post() or request('PUT', ...) are for different HTTP verbs.
  3. Final Answer:

    response = client.get('/') -> Option B
  4. Quick Check:

    GET request uses client.get() [OK]
Quick Trick: Use client.get() for GET requests in tests [OK]
Common Mistakes:
MISTAKES
  • Using post() instead of get() for GET requests
  • Using client.fetch() which does not exist
  • Confusing HTTP methods in test calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes