0PricingLogin
Flask Academy · Lesson

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 == 200

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