From 5397ce4c5e8df420ff1439a63b14766a54a581da Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Mon, 2 Dec 2024 16:08:55 -0800 Subject: [PATCH] Clean up coverage and add more tests for links in detail views --- .../gregor_anvil/tests/test_views.py | 92 ++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/gregor_django/gregor_anvil/tests/test_views.py b/gregor_django/gregor_anvil/tests/test_views.py index 5621418b..512183e1 100644 --- a/gregor_django/gregor_anvil/tests/test_views.py +++ b/gregor_django/gregor_anvil/tests/test_views.py @@ -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() @@ -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() @@ -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): @@ -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.""" @@ -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]) ) @@ -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]) ) @@ -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]) )