diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index 3ed7ac7ff..0ed602f9c 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -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 diff --git a/tests/app/main/views/test_choose_services.py b/tests/app/main/views/test_choose_accounts.py similarity index 76% rename from tests/app/main/views/test_choose_services.py rename to tests/app/main/views/test_choose_accounts.py index 44795d5c3..004c161eb 100644 --- a/tests/app/main/views/test_choose_services.py +++ b/tests/app/main/views/test_choose_accounts.py @@ -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') diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 0c5b05ff6..eb08b0314 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -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', [ diff --git a/tests/app/main/views/test_new_password.py b/tests/app/main/views/test_new_password.py index 732ae86b6..93b5a425f 100644 --- a/tests/app/main/views/test_new_password.py +++ b/tests/app/main/views/test_new_password.py @@ -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 diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py index 5757b8175..3a861c4ed 100644 --- a/tests/app/main/views/test_register.py +++ b/tests/app/main/views/test_register.py @@ -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( diff --git a/tests/app/main/views/test_sign_in.py b/tests/app/main/views/test_sign_in.py index c35a1807a..bcfaf98a4 100644 --- a/tests/app/main/views/test_sign_in.py +++ b/tests/app/main/views/test_sign_in.py @@ -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', [ diff --git a/tests/app/main/views/test_two_factor.py b/tests/app/main/views/test_two_factor.py index 3b28e5849..747dff750 100644 --- a/tests/app/main/views/test_two_factor.py +++ b/tests/app/main/views/test_two_factor.py @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index ca7627b96..a70a7ce19 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 + )