Bird
0
0

You want to test that after login, a user can access a protected page. Which sequence of test client calls is correct?

hard📝 Application Q8 of 15
Flask - Testing Flask Applications
You want to test that after login, a user can access a protected page. Which sequence of test client calls is correct?
Aclient.post('/login', data=credentials) then client.get('/protected')
Bclient.get('/protected') then client.post('/login', data=credentials)
Cclient.post('/logout') then client.get('/protected')
Dclient.get('/login') then client.get('/protected')
Step-by-Step Solution
Solution:
  1. Step 1: Understand authentication flow

    User must log in first to get session or token before accessing protected pages.
  2. Step 2: Verify correct call order

    Login POST first, then GET protected page; other orders fail or logout prevents access.
  3. Final Answer:

    client.post('/login', data=credentials) then client.get('/protected') -> Option A
  4. Quick Check:

    Login before access protected page [OK]
Quick Trick: Login first, then access protected routes in tests [OK]
Common Mistakes:
MISTAKES
  • Accessing protected page before login
  • Logging out before accessing protected page

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes