From 5efb1a6857fdcaf4c7bff9aa6ccf831d220d6cf7 Mon Sep 17 00:00:00 2001 From: nboyse Date: Mon, 18 Sep 2023 16:17:01 +0100 Subject: [PATCH] feat: test report permissions --- reports/tests/test_report_permissions.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 reports/tests/test_report_permissions.py diff --git a/reports/tests/test_report_permissions.py b/reports/tests/test_report_permissions.py new file mode 100644 index 000000000..5b2afc98a --- /dev/null +++ b/reports/tests/test_report_permissions.py @@ -0,0 +1,27 @@ +import pytest + +from django.contrib.auth.models import Group, Permission +from django.urls import reverse + +pytestmark = pytest.mark.django_db + + +def test_can_only_view_report_with_relevant_permission(client, valid_user): + client.force_login(valid_user) + response = client.get(reverse("reports:index")) + assert response.status_code == 302 + + group = Group.objects.first() + for app_label, codename in [ + ("reports", "view_report"), + ("reports", "view_report_index"), + ]: + group.permissions.add( + Permission.objects.get( + content_type__app_label=app_label, + codename=codename, + ), + ) + + valid_response = client.get(reverse("reports:index")) + assert valid_response.status_code == 200