From f9421789d0ee167659765783c1c70faf79462c96 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 9 May 2018 10:48:38 +0100 Subject: [PATCH] =?UTF-8?q?Only=20show=20=E2=80=98back=20to=20service=20na?= =?UTF-8?q?me=E2=80=99=20link=20if=20signed=20in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When you’re not signed in you can still have a service in your session. But there’s no point trying to get to its dashboard until you’re signed in – you’ll just be sent back to the ‘sign in’ page. --- app/templates/withoutnav_template.html | 2 +- .../main/views/accounts/test_choose_accounts.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/templates/withoutnav_template.html b/app/templates/withoutnav_template.html index bc55e55fc..d883559d5 100644 --- a/app/templates/withoutnav_template.html +++ b/app/templates/withoutnav_template.html @@ -2,7 +2,7 @@ {% block fullwidth_content %}
- {% if current_service %} + {% if current_service and current_user.is_authenticated %} diff --git a/tests/app/main/views/accounts/test_choose_accounts.py b/tests/app/main/views/accounts/test_choose_accounts.py index 2b0d60825..a82e9bc36 100644 --- a/tests/app/main/views/accounts/test_choose_accounts.py +++ b/tests/app/main/views/accounts/test_choose_accounts.py @@ -1,7 +1,8 @@ import pytest +from bs4 import BeautifulSoup from flask import url_for -from tests.conftest import normalize_spaces +from tests.conftest import SERVICE_ONE_ID, normalize_spaces SAMPLE_DATA = { 'organisations': [ @@ -123,3 +124,16 @@ def test_choose_account_should_not_show_back_to_service_link_if_no_service_in_se page = client_request.get('main.choose_account') assert len(page.select('.navigation-service a')) == 0 + + +def test_choose_account_should_not_show_back_to_service_link_if_not_signed_in( + client, + mock_get_service, +): + with client.session_transaction() as session: + session['service_id'] = SERVICE_ONE_ID + response = client.get(url_for('main.sign_in')) + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + + assert page.select_one('h1').text == 'Sign in' # We’re not signed in + assert page.select_one('.navigation-service a') is None