Book Image

Flask Blueprints

By : Joel Perras
Book Image

Flask Blueprints

By: Joel Perras

Overview of this book

Table of Contents (14 chapters)

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')
    assert response.status_code == 200
    assert 'Sign up!' in response.data

The preceding test first makes a request to the /users/signup route and then asserts that the HTTP response code for this route is 200 (the default...