rename choose_service to choose_account

This commit is contained in:
Leo Hemsted
2018-03-14 15:39:55 +00:00
parent 8ecbb37f71
commit 2f37e37278
19 changed files with 64 additions and 46 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ from app.main.views import ( # noqa
new_password,
styleguide,
user_profile,
choose_service,
choose_account,
api_keys,
manage_users,
invites,
@@ -6,21 +6,21 @@ from app.main import main
from app.utils import is_gov_user
@main.route("/services")
@main.route("/accounts")
@login_required
def choose_service():
def choose_account():
orgs_and_services = user_api_client.get_organisations_and_services_for_user(current_user)
return render_template(
'views/choose-service.html',
'views/choose-account.html',
organisations=orgs_and_services['organisations'],
services_without_organisations=orgs_and_services['services_without_organisations'],
can_add_service=is_gov_user(current_user.email_address)
)
@main.route("/services-or-dashboard")
def show_all_services_or_dashboard():
@main.route("/accounts-or-dashboard")
def show_accounts_or_dashboard():
if not current_user.is_authenticated:
return redirect(url_for('.index'))
@@ -39,4 +39,4 @@ def show_all_services_or_dashboard():
if len(current_user.organisations) == 1 and not current_user.services:
return redirect(url_for('.organisation_dashboard', org_id=current_user.organisations[0]))
return redirect(url_for('.choose_service'))
return redirect(url_for('.choose_account'))
+1 -1
View File
@@ -14,7 +14,7 @@ from app.main.views.sub_navigation_dictionaries import features_nav
@main.route('/')
def index():
if current_user and current_user.is_authenticated:
return redirect(url_for('main.choose_service'))
return redirect(url_for('main.choose_account'))
return render_template('views/signedout.html')
+2 -2
View File
@@ -16,7 +16,7 @@ from app.main.views.verify import activate_user
@main.route('/register', methods=['GET', 'POST'])
def register():
if current_user and current_user.is_authenticated:
return redirect(url_for('main.choose_service'))
return redirect(url_for('main.choose_account'))
form = RegisterUserForm()
if form.validate_on_submit():
@@ -101,5 +101,5 @@ def _do_registration(form, send_sms=True, send_email=True, organisation_id=None)
@main.route('/registration-continue')
def registration_continue():
if not session.get('user_details'):
return redirect(url_for('.show_all_services_or_dashboard'))
return redirect(url_for('.show_accounts_or_dashboard'))
return render_template('views/registration-continue.html')
+1 -1
View File
@@ -18,7 +18,7 @@ from app.main.forms import LoginForm
@main.route('/sign-in', methods=(['GET', 'POST']))
def sign_in():
if current_user and current_user.is_authenticated:
return redirect(url_for('main.choose_service'))
return redirect(url_for('main.choose_account'))
form = LoginForm()
+1 -1
View File
@@ -117,4 +117,4 @@ def redirect_when_logged_in(user_id):
if len(services) == 1:
return redirect(url_for('main.service_dashboard', service_id=services[0]['id']))
else:
return redirect(url_for('main.choose_service'))
return redirect(url_for('main.choose_account'))
+1 -1
View File
@@ -63,7 +63,7 @@
{% set global_header_text = "GOV.UK <span id='product-name'>Notify</span>"|safe %}
{% set homepage_url = url_for('main.show_all_services_or_dashboard') %}
{% set homepage_url = url_for('main.show_accounts_or_dashboard') %}
{% block content %}
{% block fullwidth_content %}{% endblock %}
+1 -1
View File
@@ -10,7 +10,7 @@
<div class="navigation-service-name">
{{ current_org.name }}
</div>
<a href="{{ url_for('main.choose_service') }}" class="navigation-service-switch">Switch service</a>
<a href="{{ url_for('main.choose_account') }}" class="navigation-service-switch">Switch service</a>
</div>
<div class="grid-row">
<div class="column-one-quarter">
@@ -1,13 +1,13 @@
{% extends "withoutnav_template.html" %}
{% block per_page_title %}
Choose service
Choose account
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">
Choose service
Choose account
</h1>
{% for org in organisations %}
+1 -1
View File
@@ -10,7 +10,7 @@
<div class="navigation-service-name">
{{ current_service.name }}
</div>
<a href="{{ url_for('main.choose_service') }}" class="navigation-service-switch">Switch service</a>
<a href="{{ url_for('main.choose_account') }}" class="navigation-service-switch">Switch service</a>
</div>
<div class="grid-row">
{% if help %}
+1 -1
View File
@@ -4,7 +4,7 @@
<div id="content">
{% if current_service %}
<div class="navigation-service">
<a href="{{ url_for('main.show_all_services_or_dashboard') }}">Back to {{ current_service.name }}</a>
<a href="{{ url_for('main.show_accounts_or_dashboard') }}">Back to {{ current_service.name }}</a>
</div>
{% endif %}
<main role="main">
+2 -1
View File
@@ -9,9 +9,10 @@ def test_non_gov_user_cannot_see_add_service_button(
mock_login,
mock_get_non_govuser,
api_nongov_user_active,
mock_get_organisations_and_services_for_user
):
client.login(api_nongov_user_active)
response = client.get(url_for('main.choose_service'))
response = client.get(url_for('main.choose_account'))
assert 'Add a new service' not in response.get_data(as_text=True)
assert response.status_code == 200
@@ -2,14 +2,14 @@ from bs4 import BeautifulSoup
from flask import url_for
def test_should_show_choose_services_page(
def test_should_show_choose_accounts_page(
logged_in_client,
mock_login,
mock_get_user,
api_user_active,
mock_get_services,
):
response = logged_in_client.get(url_for('main.choose_service'))
response = logged_in_client.get(url_for('main.choose_account'))
assert response.status_code == 200
resp_data = response.get_data(as_text=True)
@@ -20,14 +20,14 @@ def test_should_show_choose_services_page(
assert services['data'][1]['name'] in resp_data
def test_should_show_choose_services_page_if_no_services(
def test_should_show_choose_accounts_page_if_no_services(
logged_in_client,
mock_login,
api_user_active,
):
# if users last service has been archived there'll be no services
# mock_login already patches get_services to return no data
response = logged_in_client.get(url_for('main.choose_service'))
response = logged_in_client.get(url_for('main.choose_account'))
assert response.status_code == 200
resp_data = response.get_data(as_text=True)
assert 'Choose service' in resp_data
@@ -40,7 +40,7 @@ def test_redirect_if_only_one_service(
api_user_active,
mock_get_services_with_one_service,
):
response = logged_in_client.get(url_for('main.show_all_services_or_dashboard'))
response = logged_in_client.get(url_for('main.show_accounts_or_dashboard'))
service = mock_get_services_with_one_service.side_effect()['data'][0]
assert response.status_code == 302
@@ -52,10 +52,10 @@ def test_redirect_if_multiple_services(
mock_login,
api_user_active,
):
response = logged_in_client.get(url_for('main.show_all_services_or_dashboard'))
response = logged_in_client.get(url_for('main.show_accounts_or_dashboard'))
assert response.status_code == 302
assert response.location == url_for('main.choose_service', _external=True)
assert response.location == url_for('main.choose_account', _external=True)
def test_redirect_if_service_in_session(
@@ -67,7 +67,7 @@ def test_redirect_if_service_in_session(
):
with logged_in_client.session_transaction() as session:
session['service_id'] = '147ad62a-2951-4fa1-9ca0-093cd1a52c52'
response = logged_in_client.get(url_for('main.show_all_services_or_dashboard'))
response = logged_in_client.get(url_for('main.show_accounts_or_dashboard'))
assert response.status_code == 302
assert response.location == url_for(
@@ -81,7 +81,7 @@ def test_should_redirect_if_not_logged_in(
logged_in_client,
app_
):
response = logged_in_client.get(url_for('main.show_all_services_or_dashboard'))
response = logged_in_client.get(url_for('main.show_accounts_or_dashboard'))
assert response.status_code == 302
assert url_for('main.index', _external=True) in response.location
@@ -89,12 +89,12 @@ def test_should_redirect_if_not_logged_in(
def test_should_show_back_to_service_link(
logged_in_client
):
response = logged_in_client.get(url_for('main.choose_service'))
response = logged_in_client.get(url_for('main.choose_account'))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.select('.navigation-service a')[0]['href'] == (
url_for('main.show_all_services_or_dashboard')
url_for('main.show_accounts_or_dashboard')
)
@@ -105,7 +105,7 @@ def test_should_not_show_back_to_service_link_if_no_service_in_session(
mock_get_services_with_no_services,
):
client.login(api_user_active)
response = client.get(url_for('main.choose_service'))
response = client.get(url_for('main.choose_account'))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
+2 -2
View File
@@ -22,7 +22,7 @@ def test_non_logged_in_user_can_see_homepage(
)
def test_logged_in_user_redirects_to_choose_service(
def test_logged_in_user_redirects_to_choose_account(
logged_in_client,
api_user_active,
mock_get_user,
@@ -33,7 +33,7 @@ def test_logged_in_user_redirects_to_choose_service(
assert response.status_code == 302
response = logged_in_client.get(url_for('main.sign_in', follow_redirects=True))
assert response.location == url_for('main.choose_service', _external=True)
assert response.location == url_for('main.choose_account', _external=True)
@pytest.mark.parametrize('view', [
+1 -1
View File
@@ -100,7 +100,7 @@ def test_should_sign_in_when_password_reset_is_successful_for_email_auth(
response = client.post(url_for('.new_password', token=token), data={'new_password': 'a-new_password'})
assert response.status_code == 302
assert response.location == url_for('.choose_service', _external=True)
assert response.location == url_for('.choose_account', _external=True)
assert mock_get_user_by_email_request_password_reset.called
assert mock_reset_failed_login_count.called
+3 -3
View File
@@ -18,7 +18,7 @@ def test_render_register_returns_template_with_form(client):
assert 'Create an account' in response.get_data(as_text=True)
def test_logged_in_user_redirects_to_choose_service(
def test_logged_in_user_redirects_to_choose_account(
logged_in_client,
api_user_active,
mock_get_user_by_email,
@@ -29,7 +29,7 @@ def test_logged_in_user_redirects_to_choose_service(
assert response.status_code == 302
response = logged_in_client.get(url_for('main.sign_in', follow_redirects=True))
assert response.location == url_for('main.choose_service', _external=True)
assert response.location == url_for('main.choose_account', _external=True)
@pytest.mark.parametrize('phone_number_to_register_with', [
@@ -78,7 +78,7 @@ def test_register_continue_handles_missing_session_sensibly(
# session is not set
response = client.get(url_for('main.registration_continue'))
assert response.status_code == 302
assert response.location == url_for('main.show_all_services_or_dashboard', _external=True)
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
def test_process_register_returns_200_when_mobile_number_is_invalid(
+9 -6
View File
@@ -38,12 +38,15 @@ def test_sign_in_explains_other_browser(logged_in_client, api_user_active, mocke
assert 'We signed you out because you logged in to Notify on another device' in response.get_data(as_text=True)
def test_doesnt_redirect_to_sign_in_if_no_session_info(logged_in_client, api_user_active):
def test_doesnt_redirect_to_sign_in_if_no_session_info(
logged_in_client, api_user_active
):
assert api_user_active.current_session_id is None
with logged_in_client.session_transaction() as session:
session['current_session_id'] = None
response = logged_in_client.get(url_for('main.choose_service'))
response = logged_in_client.get(url_for('main.add_service'))
assert response.status_code == 200
@@ -65,16 +68,16 @@ def test_redirect_to_sign_in_if_logged_in_from_other_browser(
with logged_in_client.session_transaction() as session:
session['current_session_id'] = str(cookie_sess_id)
response = logged_in_client.get(url_for('main.choose_service'))
response = logged_in_client.get(url_for('main.choose_account'))
assert response.status_code == 302
assert response.location == url_for('main.sign_in', next='/services', _external=True)
assert response.location == url_for('main.sign_in', next='/accounts', _external=True)
def test_logged_in_user_redirects_to_choose_service(
def test_logged_in_user_redirects_to_choose_account(
logged_in_client
):
response = logged_in_client.get(url_for('main.sign_in'))
assert response.location == url_for('main.choose_service', _external=True)
assert response.location == url_for('main.choose_account', _external=True)
@pytest.mark.parametrize('email_address, password', [
+3 -3
View File
@@ -90,7 +90,7 @@ def test_should_login_user_and_not_redirect_to_external_url(
)
def test_should_login_user_and_redirect_to_choose_services(
def test_should_login_user_and_redirect_to_choose_accounts(
client,
api_user_active,
mock_get_user,
@@ -106,7 +106,7 @@ def test_should_login_user_and_redirect_to_choose_services(
data={'sms_code': '12345'})
assert response.status_code == 302
assert response.location == url_for('main.choose_service', _external=True)
assert response.location == url_for('main.choose_account', _external=True)
def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(
@@ -321,4 +321,4 @@ def test_two_factor_email_link_used_when_user_already_logged_in(
url_for('main.two_factor_email', token=valid_token)
)
assert response.status_code == 302
assert response.location == url_for('main.choose_service', _external=True)
assert response.location == url_for('main.choose_account', _external=True)
+14
View File
@@ -2867,3 +2867,17 @@ def mock_update_organisation_name(mocker):
return
return mocker.patch('app.organisations_client.update_organisation_name', side_effect=_update_org_name)
@pytest.fixture
def mock_get_organisations_and_services_for_user(mocker, organisation_one, api_user_active):
def _get_orgs_and_services(user_id):
return {
'organisations': [],
'services_without_organisations': []
}
return mocker.patch(
'app.user_api_client.get_organisations_and_services_for_user',
side_effect=_get_orgs_and_services
)