From 9b91132276e6c52cc827c5d5e0b947afb7e87cae Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 31 Oct 2019 09:43:16 +0000 Subject: [PATCH] Test that static pages work w/out current_service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you sign in, don’t choose a service then navigate to a state page then it’s possible `current_service` won’t be set, in which case you shouldn’t be generating URLs that need `current_service.id`. --- tests/app/main/views/test_index.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index d66a7fa6d..0bb249db1 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -1,3 +1,4 @@ +from functools import partial import pytest from bs4 import BeautifulSoup from flask import url_for @@ -81,14 +82,23 @@ def test_static_pages( mock_get_organisation_by_domain, view, ): - page = client_request.get('main.{}'.format(view)) + request = partial(client_request.get, 'main.{}'.format(view)) + + # Check the page loads when user is signed in + page = request() assert not page.select_one('meta[name=description]') + # Check it still works when they don’t have a recent service + with client_request.session_transaction() as session: + session['service_id'] = None + request() + + # Check it still works when they sign out client_request.logout() with client_request.session_transaction() as session: session['service_id'] = None session['user_id'] = None - client_request.get('main.{}'.format(view)) + request() @pytest.mark.parametrize('view, expected_view', [