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 == 302All lessons in this course
- The Test Client and Fixtures
- Assert on Routes and JSON
- Isolate Tests with a Test Database
- Test Authenticated Endpoints