Assert on Routes and JSON
Check status codes and response bodies.
What You Assert
A good route test checks two things: the right status code and the right body. If both match, you know the endpoint behaves as promised.
Check the Status Code
The response carries a status_code attribute. A healthy page returns 200, so assert on it to confirm the route loaded without error.
resp = client.get('/')
assert resp.status_code == 200All lessons in this course
- The Test Client and Fixtures
- Assert on Routes and JSON
- Isolate Tests with a Test Database
- Test Authenticated Endpoints