Add tests to check permission-restricted broadcast pages

Some pages should only be shown to users who have permission to send or
approve broadcasts. This commit adds a test to ensure that this is true,
and that we don’t accidentally regress the checks for this permission.
This commit is contained in:
Chris Hill-Scott
2020-08-10 12:26:33 +01:00
parent 78c88530b5
commit e47dbc0caa

View File

@@ -75,6 +75,63 @@ def test_broadcast_pages_403_without_permission(
)
@pytest.mark.parametrize('endpoint, extra_args, expected_get_status, expected_post_status', (
(
'.broadcast',
{'template_id': sample_uuid},
403, 405,
),
(
'.preview_broadcast_areas', {'broadcast_message_id': sample_uuid},
403, 405,
),
(
'.choose_broadcast_library', {'broadcast_message_id': sample_uuid},
403, 405,
),
(
'.choose_broadcast_area', {'broadcast_message_id': sample_uuid, 'library_slug': 'countries'},
403, 403,
),
(
'.remove_broadcast_area', {'broadcast_message_id': sample_uuid, 'area_slug': 'england'},
403, 405,
),
(
'.preview_broadcast_message', {'broadcast_message_id': sample_uuid},
403, 403,
),
(
'.cancel_broadcast_message', {'broadcast_message_id': sample_uuid},
403, 403,
),
))
def test_broadcast_pages_403_for_user_without_permission(
mocker,
client_request,
service_one,
active_user_view_permissions,
endpoint,
extra_args,
expected_get_status,
expected_post_status,
):
service_one['permissions'] += ['broadcast']
mocker.patch('app.user_api_client.get_user', return_value=active_user_view_permissions)
client_request.get(
endpoint,
service_id=SERVICE_ONE_ID,
_expected_status=expected_get_status,
**extra_args
)
client_request.post(
endpoint,
service_id=SERVICE_ONE_ID,
_expected_status=expected_post_status,
**extra_args
)
def test_dashboard_redirects_to_broadcast_dashboard(
client_request,
service_one,
@@ -94,6 +151,7 @@ def test_dashboard_redirects_to_broadcast_dashboard(
def test_empty_broadcast_dashboard(
client_request,
service_one,
active_user_view_permissions,
mock_get_no_broadcast_messages,
mock_get_service_templates_when_no_templates_exist,
):
@@ -157,6 +215,7 @@ def test_broadcast_dashboard(
def test_broadcast_dashboard_json(
logged_in_client,
service_one,
active_user_view_permissions,
mock_get_broadcast_messages,
):
service_one['permissions'] += ['broadcast']