Skip to content

Commit

Permalink
Clean up coverage and add more tests for links in detail views
Browse files Browse the repository at this point in the history
  • Loading branch information
amstilp committed Dec 3, 2024
1 parent 0891a0f commit 5397ce4
Showing 1 changed file with 90 additions and 2 deletions.
92 changes: 90 additions & 2 deletions gregor_django/gregor_anvil/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ def setUp(self):
# Create a user with both view and edit permission.
self.user = User.objects.create_user(username="test", password="test")
self.user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME)
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME)
)
self.object = factories.TemplateWorkspaceFactory.create()

Expand Down Expand Up @@ -2222,7 +2222,7 @@ def setUp(self):
# Create a user with both view and edit permission.
self.user = User.objects.create_user(username="test", password="test")
self.user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME)
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME)
)
self.object = factories.ReleaseWorkspaceFactory.create()

Expand Down Expand Up @@ -2278,6 +2278,50 @@ def test_contains_upload_workspaces_from_previous_cycles(self):
response.context_data["included_workspace_table"].data,
)

def test_links_view_user(self):
user = self.user
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)
self.assertNotContains(
response, reverse("gregor_anvil:consent_groups:detail", args=[self.object.consent_group.pk])
)

def test_links_staff_view_user(self):
user = User.objects.create_user(username="test-staff-view", password="test-staff-view")
user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME)
)
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
# Links to other resources
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)
self.assertContains(
response, reverse("gregor_anvil:consent_groups:detail", args=[self.object.consent_group.pk])
)

def test_links_staff_edit_user(self):
user = User.objects.create_user(username="test-staff-view", password="test-staff-view")
user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME)
)
user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_EDIT_PERMISSION_CODENAME)
)
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
# Links to other resources
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)
self.assertContains(
response, reverse("gregor_anvil:consent_groups:detail", args=[self.object.consent_group.pk])
)


class WorkspaceReportTest(TestCase):
def setUp(self):
Expand Down Expand Up @@ -2499,6 +2543,41 @@ def test_status_code(self):
response = self.client.get(self.get_url(self.object.workspace.billing_project.name, self.object.workspace.name))
self.assertEqual(response.status_code, 200)

def test_links_view_user(self):
user = self.user
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)

def test_links_staff_view_user(self):
user = User.objects.create_user(username="test-staff-view", password="test-staff-view")
user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME)
)
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
# Links to other resources
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)

def test_links_staff_edit_user(self):
user = User.objects.create_user(username="test-staff-view", password="test-staff-view")
user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME)
)
user.user_permissions.add(
Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.STAFF_EDIT_PERMISSION_CODENAME)
)
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
# Links to other resources
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)


class DCCProcessedDataWorkspaceListTest(TestCase):
"""Tests of the anvil_consortium_manager WorkspaceList view using this app's adapter."""
Expand Down Expand Up @@ -2563,6 +2642,9 @@ def test_links_view_user(self):
user = self.user
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)
self.assertNotContains(
response, reverse("gregor_anvil:consent_groups:detail", args=[self.object.consent_group.pk])
)
Expand All @@ -2575,6 +2657,9 @@ def test_links_staff_view_user(self):
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
# Links to other resources
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)
self.assertContains(
response, reverse("gregor_anvil:consent_groups:detail", args=[self.object.consent_group.pk])
)
Expand All @@ -2589,6 +2674,9 @@ def test_links_staff_edit_user(self):
)
self.client.force_login(user)
response = self.client.get(self.object.get_absolute_url())
self.assertContains(
response, reverse("gregor_anvil:upload_cycles:detail", args=[self.object.upload_cycle.cycle])
)
self.assertContains(
response, reverse("gregor_anvil:consent_groups:detail", args=[self.object.consent_group.pk])
)
Expand Down

0 comments on commit 5397ce4

Please sign in to comment.