Merge pull request #494 from alphagov/click-govuk-not-logged-in

If not logged in, go to homepage when clicking GOV.UK
This commit is contained in:
Chris Hill-Scott
2016-04-25 15:33:36 +01:00
2 changed files with 29 additions and 3 deletions

View File

@@ -16,8 +16,11 @@ def choose_service():
@main.route("/services-or-dashboard")
@login_required
def show_all_services_or_dashboard():
if not current_user.is_authenticated():
return redirect(url_for('.index'))
services = service_api_client.get_services({'user_id': current_user.id})['data']
if 1 == len(services):

View File

@@ -1,4 +1,4 @@
from flask import url_for
from flask import url_for, session
def test_should_show_choose_services_page(app_,
@@ -54,12 +54,35 @@ def test_redirect_if_multiple_services(
assert response.location == url_for('main.choose_service', _external=True)
def test_redirect_if_service_in_session(
app_,
mock_login,
mock_get_user,
api_user_active,
mock_get_services,
mock_get_service
):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
with client.session_transaction() as session:
session['service_id'] = '147ad62a-2951-4fa1-9ca0-093cd1a52c52'
response = client.get(url_for('main.show_all_services_or_dashboard'))
assert response.status_code == 302
assert response.location == url_for(
'main.service_dashboard',
service_id='147ad62a-2951-4fa1-9ca0-093cd1a52c52',
_external=True
)
def test_should_redirect_if_not_logged_in(app_):
with app_.test_request_context():
with app_.test_client() as client:
response = client.get(url_for('main.show_all_services_or_dashboard'))
assert response.status_code == 302
assert url_for('main.sign_in', _external=True) in response.location
assert url_for('main.index', _external=True) in response.location
def test_should_show_all_services_for_platform_admin_user(app_,