0Pricing
Flask Academy · Lesson

Test Authenticated Endpoints

Log in inside tests to reach guarded routes.

The Challenge of Auth Tests

Protected routes refuse anonymous visitors. To test them, your client must first log in, just like a real user would before reaching guarded pages.

Confirm the Guard Works

Start by proving the gate is closed. Request the route logged out and assert you get a redirect or a 401 response.

resp = client.get('/dashboard')
assert resp.status_code == 302

All lessons in this course

  1. The Test Client and Fixtures
  2. Assert on Routes and JSON
  3. Isolate Tests with a Test Database
  4. Test Authenticated Endpoints
← Back to Flask Academy