Make test more robust

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
This commit is contained in:
Chris Hill-Scott
2020-02-11 11:08:35 +00:00
parent cceb731596
commit 8a4bf1d07e

View File

@@ -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):