O'Reilly logo

Flask Blueprints by Joël Perras

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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') ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required