Skip to content

Commit

Permalink
feat: test report permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
nboyse committed Sep 18, 2023
1 parent 8e2f18b commit 5efb1a6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions reports/tests/test_report_permissions.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5efb1a6

Please sign in to comment.