From 8a4bf1d07e61a920f91aa52fe9c17f51245cfd72 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 11 Feb 2020 11:08:35 +0000 Subject: [PATCH] Make test more robust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now tests: - that the user doesn’t have the usage menu item when they’re not a member of the organisation (i.e. the counterfactual) - that the user still gets a 403 when they try to view the usage page if they’re not a member of the organisation --- tests/app/main/test_permissions.py | 48 +++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/tests/app/main/test_permissions.py b/tests/app/main/test_permissions.py index 09a6d7b1d..4156001f2 100644 --- a/tests/app/main/test_permissions.py +++ b/tests/app/main/test_permissions.py @@ -378,7 +378,28 @@ def test_service_navigation_for_org_user( ] -def test_org_user_who_is_also_service_user_can_still_see_usage_page( +@pytest.mark.parametrize('user_organisations, expected_menu_items, expected_status', [ + ( + [], + ( + 'Templates', + 'Sent messages', + 'Team members', + ), + 403, + ), + ( + [ORGANISATION_ID], + ( + 'Templates', + 'Sent messages', + 'Team members', + 'Usage', + ), + 200, + ), +]) +def test_service_user_without_manage_service_permission_can_see_usage_page_when_org_user( client_request, mocker, active_caseworking_user, @@ -390,9 +411,14 @@ def test_org_user_who_is_also_service_user_can_still_see_usage_page( mock_get_invites_for_service, mock_get_users_by_service, mock_get_service_organisation, + mock_get_service_templates, + mock_get_template_folders, + user_organisations, + expected_status, + expected_menu_items, ): active_caseworking_user['services'] = [SERVICE_ONE_ID] - active_caseworking_user['organisations'] = [ORGANISATION_ID] + active_caseworking_user['organisations'] = user_organisations service = service_json( id_=SERVICE_ONE_ID, organisation_id=ORGANISATION_ID, @@ -402,19 +428,19 @@ def test_org_user_who_is_also_service_user_can_still_see_usage_page( return_value={'data': service} ) client_request.login(active_caseworking_user, service=service) - page = client_request.get( - 'main.usage', + 'main.choose_template', service_id=SERVICE_ONE_ID, ) - assert [ + assert tuple( item.text.strip() for item in page.select('nav.navigation a') - ] == [ - 'Templates', - 'Sent messages', - 'Team members', - 'Usage', - ] + ) == expected_menu_items + + client_request.get( + 'main.usage', + service_id=SERVICE_ONE_ID, + _expected_status=expected_status, + ) def get_name_of_decorator_from_ast_node(node):