Functional testing
Now that we created a few routes and templates to handle user signup and login, let's utilize some of the py.test
knowledge that we gained earlier in the chapter in order to write some post facto integration tests to ensure that our views are behaving as we expect. First, let's create a new test module in application/tests/test_user_views.py
and write our first test that uses the client fixture so as to simulate a request to the application via the built-in Werkzeug test client. This will ensure that a proper request context has been constructed so that the context bound objects (for example, url_for
, g
) are available, as follows:
def test_get_user_signup_page(client): """Ensure signup page is available.""" response = client.get('/users/signup') ...
Get Flask Blueprints now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.