-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |