diff --git a/gregor_django/gregor_anvil/adapters.py b/gregor_django/gregor_anvil/adapters.py index f0192b27..f6939c8a 100644 --- a/gregor_django/gregor_anvil/adapters.py +++ b/gregor_django/gregor_anvil/adapters.py @@ -143,7 +143,7 @@ class PartnerUploadWorkspaceAdapter(WorkspaceAdminSharingAdapterMixin, BaseWorks name = "Partner upload workspace" description = "Workspaces that contain data uploaded by a Partner Group " list_table_class_view = tables.PartnerUploadWorkspaceTable - list_table_class_staff_view = tables.PartnerUploadWorkspaceTable + list_table_class_staff_view = tables.PartnerUploadWorkspaceStaffTable workspace_data_model = models.PartnerUploadWorkspace workspace_data_form_class = forms.PartnerUploadWorkspaceForm @@ -160,7 +160,7 @@ class ResourceWorkspaceAdapter(WorkspaceAdminSharingAdapterMixin, BaseWorkspaceA "Workspaces that contain general Consortium resources (e.g., examples of using AnVIL, working with data, etc.)" # noqa: E501 ) list_table_class_view = tables.DefaultWorkspaceTable - list_table_class_staff_view = tables.DefaultWorkspaceTable + list_table_class_staff_view = tables.DefaultWorkspaceStaffTable workspace_data_model = models.ResourceWorkspace workspace_data_form_class = forms.ResourceWorkspaceForm workspace_detail_template_name = "gregor_anvil/resourceworkspace_detail.html" @@ -245,7 +245,7 @@ class ExchangeWorkspaceAdapter(WorkspaceAdminSharingAdapterMixin, BaseWorkspaceA name = "Exchange workspace" description = "Workspaces for exchanging data with a Research Center outside of an upload cycle" list_table_class_view = tables.ExchangeWorkspaceTable - list_table_class_staff_view = tables.ExchangeWorkspaceTable + list_table_class_staff_view = tables.ExchangeWorkspaceStaffTable workspace_data_model = models.ExchangeWorkspace workspace_data_form_class = forms.ExchangeWorkspaceForm workspace_form_class = WorkspaceForm diff --git a/gregor_django/gregor_anvil/tables.py b/gregor_django/gregor_anvil/tables.py index 23ac7857..d35922cf 100644 --- a/gregor_django/gregor_anvil/tables.py +++ b/gregor_django/gregor_anvil/tables.py @@ -154,9 +154,24 @@ def render_consortium_access(self, record): class DefaultWorkspaceTable(WorkspaceConsortiumAccessTable, tables.Table): - """Class to use for default workspace tables in GREGoR.""" + """Class to use for default workspace tables in GREGoR for view users.""" name = tables.Column(linkify=True, verbose_name="Workspace") + billing_project = tables.Column() + + class Meta: + model = Workspace + fields = ( + "name", + "billing_project", + "consortium_access", + ) + order_by = ("name",) + + +class DefaultWorkspaceStaffTable(DefaultWorkspaceTable): + """Class to use for default workspace tables in GREGoR for staff users.""" + billing_project = tables.Column(linkify=True) number_groups = tables.Column( verbose_name="Number of groups shared with", @@ -165,15 +180,13 @@ class DefaultWorkspaceTable(WorkspaceConsortiumAccessTable, tables.Table): accessor="workspacegroupsharing_set__count", ) - class Meta: - model = Workspace + class Meta(DefaultWorkspaceTable.Meta): fields = ( "name", "billing_project", "number_groups", "consortium_access", ) - order_by = ("name",) class UploadWorkspaceTable(WorkspaceConsortiumAccessTable, tables.Table): @@ -198,7 +211,7 @@ class PartnerUploadWorkspaceTable(WorkspaceConsortiumAccessTable, tables.Table): """A table for Workspaces that includes fields from PartnerUploadWorkspace.""" name = tables.columns.Column(linkify=True) - partneruploadworkspace__partner_group = tables.columns.Column(linkify=True) + partneruploadworkspace__partner_group = tables.columns.Column() class Meta: model = Workspace @@ -212,6 +225,12 @@ class Meta: ) +class PartnerUploadWorkspaceStaffTable(PartnerUploadWorkspaceTable): + """A table for Workspaces that includes fields from PartnerUploadWorkspace.""" + + partneruploadworkspace__partner_group = tables.columns.Column(linkify=True) + + class TemplateWorkspaceTable(WorkspaceConsortiumAccessTable, tables.Table): """A table for Workspaces that includes fields from TemplateWorkspace.""" @@ -279,6 +298,7 @@ class DCCProcessingWorkspaceTable(tables.Table): """A table for Workspaces that includes fields from DCCProcessingWorkspace.""" name = tables.columns.Column(linkify=True) + dccprocessingworkspace__upload_cycle = tables.columns.Column(linkify=True) class Meta: model = Workspace @@ -293,7 +313,7 @@ class DCCProcessedDataWorkspaceTable(WorkspaceConsortiumAccessTable, tables.Tabl """A table for Workspaces that includes fields from DCCProcessedDataWorkspace.""" name = tables.columns.Column(linkify=True) - dccprocesseddataworkspace__consent_group = tables.columns.Column(linkify=True) + dccprocesseddataworkspace__upload_cycle = tables.columns.Column(linkify=True) class Meta: model = Workspace @@ -309,10 +329,17 @@ class ExchangeWorkspaceTable(tables.Table): """Class to use for ExchangeWorkspace tables.""" name = tables.Column(linkify=True, verbose_name="Workspace") - billing_project = tables.Column(linkify=True) - exchangeworkspace__research_center = tables.Column(linkify=True) + billing_project = tables.Column() + exchangeworkspace__research_center = tables.Column() class Meta: model = Workspace fields = ("name", "billing_project", "exchangeworkspace__research_center") order_by = ("name",) + + +class ExchangeWorkspaceStaffTable(ExchangeWorkspaceTable): + """Class to use for ExchangeWorkspace tables.""" + + billing_project = tables.Column(linkify=True) + exchangeworkspace__research_center = tables.Column(linkify=True) diff --git a/gregor_django/gregor_anvil/tests/test_tables.py b/gregor_django/gregor_anvil/tests/test_tables.py index fb5d90c4..01a8434f 100644 --- a/gregor_django/gregor_anvil/tests/test_tables.py +++ b/gregor_django/gregor_anvil/tests/test_tables.py @@ -268,10 +268,10 @@ def test_is_shared_one_auth_domain_shared_with_different_group_in_auth_domain(se self.assertNotIn("check-circle-fill", table.render_consortium_access(workspace)) -class UploadWorkspaceTableTest(TestCase): +class DefaultWorkspaceTableTest(TestCase): model = Workspace - model_factory = factories.UploadWorkspaceFactory - table_class = tables.UploadWorkspaceTable + model_factory = factories.WorkspaceFactory + table_class = tables.DefaultWorkspaceTable def test_row_count_with_no_objects(self): table = self.table_class(self.model.objects.all()) @@ -289,10 +289,10 @@ def test_row_count_with_two_objects(self): self.assertEqual(len(table.rows), 2) -class PartnerUploadWorkspaceTableTest(TestCase): +class DefaultWorkspaceStaffTableTest(TestCase): model = Workspace - model_factory = factories.PartnerUploadWorkspaceFactory - table_class = tables.PartnerUploadWorkspaceTable + model_factory = factories.WorkspaceFactory + table_class = tables.DefaultWorkspaceStaffTable def test_row_count_with_no_objects(self): table = self.table_class(self.model.objects.all()) @@ -309,11 +309,22 @@ def test_row_count_with_two_objects(self): table = self.table_class(self.model.objects.all()) self.assertEqual(len(table.rows), 2) + def test_number_groups(self): + self.model_factory.create(name="aaa") + workspace_2 = self.model_factory.create(name="bbb") + workspace_3 = self.model_factory.create(name="ccc") + WorkspaceGroupSharingFactory.create_batch(1, workspace=workspace_2) + WorkspaceGroupSharingFactory.create_batch(2, workspace=workspace_3) + table = self.table_class(self.model.objects.all()) + self.assertEqual(table.rows[0].get_cell("number_groups"), 0) + self.assertEqual(table.rows[1].get_cell("number_groups"), 1) + self.assertEqual(table.rows[2].get_cell("number_groups"), 2) -class TemplateWorkspaceTableTest(TestCase): + +class UploadWorkspaceTableTest(TestCase): model = Workspace - model_factory = factories.TemplateWorkspaceFactory - table_class = tables.TemplateWorkspaceTable + model_factory = factories.UploadWorkspaceFactory + table_class = tables.UploadWorkspaceTable def test_row_count_with_no_objects(self): table = self.table_class(self.model.objects.all()) @@ -331,12 +342,10 @@ def test_row_count_with_two_objects(self): self.assertEqual(len(table.rows), 2) -class CombinedConsortiumDataWorkspaceTableTest(TestCase): - """Tests for the AccountTable in this app.""" - +class PartnerUploadWorkspaceTableTest(TestCase): model = Workspace - model_factory = factories.CombinedConsortiumDataWorkspaceFactory - table_class = tables.CombinedConsortiumDataWorkspaceTable + model_factory = factories.PartnerUploadWorkspaceFactory + table_class = tables.PartnerUploadWorkspaceTable def test_row_count_with_no_objects(self): table = self.table_class(self.model.objects.all()) @@ -348,17 +357,37 @@ def test_row_count_with_one_object(self): self.assertEqual(len(table.rows), 1) def test_row_count_with_two_objects(self): + # These values are coded into the model, so need to create separately. self.model_factory.create_batch(2) table = self.table_class(self.model.objects.all()) self.assertEqual(len(table.rows), 2) -class ReleaseWorkspaceTableTest(TestCase): - """Tests for the AccountTable in this app.""" +class PartnerUploadWorkspaceStaffTableTest(TestCase): + model = Workspace + model_factory = factories.PartnerUploadWorkspaceFactory + table_class = tables.PartnerUploadWorkspaceStaffTable + + def test_row_count_with_no_objects(self): + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 0) + def test_row_count_with_one_object(self): + self.model_factory.create() + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 1) + + def test_row_count_with_two_objects(self): + # These values are coded into the model, so need to create separately. + self.model_factory.create_batch(2) + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 2) + + +class TemplateWorkspaceTableTest(TestCase): model = Workspace - model_factory = factories.ReleaseWorkspaceFactory - table_class = tables.ReleaseWorkspaceTable + model_factory = factories.TemplateWorkspaceFactory + table_class = tables.TemplateWorkspaceTable def test_row_count_with_no_objects(self): table = self.table_class(self.model.objects.all()) @@ -370,6 +399,7 @@ def test_row_count_with_one_object(self): self.assertEqual(len(table.rows), 1) def test_row_count_with_two_objects(self): + # These values are coded into the model, so need to create separately. self.model_factory.create_batch(2) table = self.table_class(self.model.objects.all()) self.assertEqual(len(table.rows), 2) @@ -411,6 +441,50 @@ def test_row_count_with_two_workspace_types(self): self.assertEqual(len(table.rows), 2) +class CombinedConsortiumDataWorkspaceTableTest(TestCase): + """Tests for the AccountTable in this app.""" + + model = Workspace + model_factory = factories.CombinedConsortiumDataWorkspaceFactory + table_class = tables.CombinedConsortiumDataWorkspaceTable + + def test_row_count_with_no_objects(self): + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 0) + + def test_row_count_with_one_object(self): + self.model_factory.create() + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 1) + + def test_row_count_with_two_objects(self): + self.model_factory.create_batch(2) + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 2) + + +class ReleaseWorkspaceTableTest(TestCase): + """Tests for the AccountTable in this app.""" + + model = Workspace + model_factory = factories.ReleaseWorkspaceFactory + table_class = tables.ReleaseWorkspaceTable + + def test_row_count_with_no_objects(self): + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 0) + + def test_row_count_with_one_object(self): + self.model_factory.create() + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 1) + + def test_row_count_with_two_objects(self): + self.model_factory.create_batch(2) + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 2) + + class DCCProcessingWorkspaceTableTest(TestCase): model = Workspace model_factory = factories.DCCProcessingWorkspaceFactory @@ -472,3 +546,24 @@ def test_row_count_with_two_objects(self): self.model_factory.create_batch(2) table = self.table_class(self.model.objects.all()) self.assertEqual(len(table.rows), 2) + + +class ExchangeWorkspaceStaffTableTest(TestCase): + model = Workspace + model_factory = factories.ExchangeWorkspaceFactory + table_class = tables.ExchangeWorkspaceStaffTable + + def test_row_count_with_no_objects(self): + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 0) + + def test_row_count_with_one_object(self): + self.model_factory.create() + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 1) + + def test_row_count_with_two_objects(self): + # These values are coded into the model, so need to create separately. + self.model_factory.create_batch(2) + table = self.table_class(self.model.objects.all()) + self.assertEqual(len(table.rows), 2) diff --git a/gregor_django/gregor_anvil/tests/test_views.py b/gregor_django/gregor_anvil/tests/test_views.py index 01e9d227..5621418b 100644 --- a/gregor_django/gregor_anvil/tests/test_views.py +++ b/gregor_django/gregor_anvil/tests/test_views.py @@ -24,7 +24,7 @@ from gregor_django.users.tables import UserTable from gregor_django.users.tests.factories import UserFactory -from .. import forms, models, tables, views +from .. import adapters, forms, models, tables, views from ..audit import ( combined_workspace_audit, upload_workspace_audit, @@ -1493,12 +1493,23 @@ def get_url(self, *args): """Get the url for the view being tested.""" return reverse("anvil_consortium_manager:workspaces:list", args=args) - def test_view_has_correct_table_class(self): + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.UploadWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): """The view has the correct table class in the context.""" self.client.force_login(self.user) response = self.client.get(self.get_url(self.workspace_type)) self.assertIn("table", response.context_data) - self.assertIsInstance(response.context_data["table"], tables.UploadWorkspaceTable) + self.assertIs(type(response.context_data["table"]), tables.UploadWorkspaceTable) class UploadWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase): @@ -1752,12 +1763,23 @@ def get_url(self, *args): """Get the url for the view being tested.""" return reverse("anvil_consortium_manager:workspaces:list", args=args) - def test_view_has_correct_table_class(self): + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.DefaultWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): """The view has the correct table class in the context.""" self.client.force_login(self.user) response = self.client.get(self.get_url(self.workspace_type)) self.assertIn("table", response.context_data) - self.assertIsInstance(response.context_data["table"], tables.DefaultWorkspaceTable) + self.assertIs(type(response.context_data["table"]), tables.DefaultWorkspaceStaffTable) class ResourceWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase): @@ -1882,12 +1904,23 @@ def get_url(self, *args): """Get the url for the view being tested.""" return reverse("anvil_consortium_manager:workspaces:list", args=args) - def test_view_has_correct_table_class(self): + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.TemplateWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): """The view has the correct table class in the context.""" self.client.force_login(self.user) response = self.client.get(self.get_url(self.workspace_type)) self.assertIn("table", response.context_data) - self.assertIsInstance(response.context_data["table"], tables.TemplateWorkspaceTable) + self.assertIs(type(response.context_data["table"]), tables.TemplateWorkspaceTable) class TemplateWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase): @@ -1971,6 +2004,42 @@ def test_creates_upload_workspace(self): self.assertEqual(new_workspace_data.intended_use, "foo bar") +class ConsortiumCombinedDataWorkspaceListTest(TestCase): + """Tests of the anvil_consortium_manager WorkspaceList view using this app's adapter.""" + + def setUp(self): + """Set up test class.""" + self.factory = RequestFactory() + # 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) + ) + self.workspace_type = "combined_consortium" + + def get_url(self, *args): + """Get the url for the view being tested.""" + return reverse("anvil_consortium_manager:workspaces:list", args=args) + + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.CombinedConsortiumDataWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): + """The view has the correct table class in the context.""" + self.client.force_login(self.user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.CombinedConsortiumDataWorkspaceTable) + + class ConsortiumCombinedDataWorkspaceDetailTest(TestCase): """Tests of the anvil_consortium_manager WorkspaceDetail view using the CombinedConsortiumDataWorkspace adapter.""" @@ -2108,6 +2177,42 @@ def test_links_staff_edit_user(self): self.assertContains(response, url) +class ReleaseWorkspaceListTest(TestCase): + """Tests of the anvil_consortium_manager WorkspaceList view using this app's adapter.""" + + def setUp(self): + """Set up test class.""" + self.factory = RequestFactory() + # 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) + ) + self.workspace_type = "release" + + def get_url(self, *args): + """Get the url for the view being tested.""" + return reverse("anvil_consortium_manager:workspaces:list", args=args) + + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.ReleaseWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): + """The view has the correct table class in the context.""" + self.client.force_login(self.user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.ReleaseWorkspaceTable) + + class ReleaseWorkspaceDetailTest(TestCase): """Tests of the anvil_consortium_manager WorkspaceDetail view using the ReleaseWorkspaceAdapter.""" @@ -2335,6 +2440,42 @@ def test_correct_count_consortium_members_with_access_to_workspaces_in_context( self.assertEqual(response.context_data["verified_linked_accounts"], 1) +class DCCProcessingWorkspaceListTest(TestCase): + """Tests of the anvil_consortium_manager WorkspaceList view using this app's adapter.""" + + def setUp(self): + """Set up test class.""" + self.factory = RequestFactory() + # 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) + ) + self.workspace_type = "dcc_processing" + + def get_url(self, *args): + """Get the url for the view being tested.""" + return reverse("anvil_consortium_manager:workspaces:list", args=args) + + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.DCCProcessingWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): + """The view has the correct table class in the context.""" + self.client.force_login(self.user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.DCCProcessingWorkspaceTable) + + class DCCProcessingWorkspaceDetailTest(TestCase): """Tests of the anvil_consortium_manager WorkspaceDetail view using the DCCProcessingWorkspace adapter.""" @@ -2359,6 +2500,42 @@ def test_status_code(self): self.assertEqual(response.status_code, 200) +class DCCProcessedDataWorkspaceListTest(TestCase): + """Tests of the anvil_consortium_manager WorkspaceList view using this app's adapter.""" + + def setUp(self): + """Set up test class.""" + self.factory = RequestFactory() + # 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) + ) + self.workspace_type = "dcc_processed_data" + + def get_url(self, *args): + """Get the url for the view being tested.""" + return reverse("anvil_consortium_manager:workspaces:list", args=args) + + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.DCCProcessedDataWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): + """The view has the correct table class in the context.""" + self.client.force_login(self.user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.DCCProcessedDataWorkspaceTable) + + class DCCProcessedDataWorkspaceDetailTest(TestCase): """Tests of the anvil_consortium_manager WorkspaceDetail view using the DCCProcessedDataWorkspace adapter.""" @@ -2492,12 +2669,23 @@ def get_url(self, *args): """Get the url for the view being tested.""" return reverse("anvil_consortium_manager:workspaces:list", args=args) - def test_view_has_correct_table_class(self): + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.ExchangeWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): """The view has the correct table class in the context.""" self.client.force_login(self.user) response = self.client.get(self.get_url(self.workspace_type)) self.assertIn("table", response.context_data) - self.assertIsInstance(response.context_data["table"], tables.ExchangeWorkspaceTable) + self.assertIs(type(response.context_data["table"]), tables.ExchangeWorkspaceStaffTable) class ExchangeWorkspaceCreateTest(AnVILAPIMockTestMixin, TestCase): @@ -2649,6 +2837,42 @@ def test_links_staff_edit_user(self): ) +class PartnerUploadWorkspaceListTest(TestCase): + """Tests of the anvil_consortium_manager WorkspaceList view using this app's adapter.""" + + def setUp(self): + """Set up test class.""" + self.factory = RequestFactory() + # 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) + ) + self.workspace_type = adapters.PartnerUploadWorkspaceAdapter().get_type() + + def get_url(self, *args): + """Get the url for the view being tested.""" + return reverse("anvil_consortium_manager:workspaces:list", args=args) + + def test_view_has_correct_table_class_view_user(self): + """The view has the correct table class in the context.""" + user = User.objects.create_user(username="test-view", password="test-view") + user.user_permissions.add( + Permission.objects.get(codename=acm_models.AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME) + ) + self.client.force_login(user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.PartnerUploadWorkspaceTable) + + def test_view_has_correct_table_class_staff_view_user(self): + """The view has the correct table class in the context.""" + self.client.force_login(self.user) + response = self.client.get(self.get_url(self.workspace_type)) + self.assertIn("table", response.context_data) + self.assertIs(type(response.context_data["table"]), tables.PartnerUploadWorkspaceStaffTable) + + class ManagedGroupCreateTest(AnVILAPIMockTestMixin, TestCase): """Tests for custom ManagedGroup behavior."""