Skip to content

Commit

Permalink
Split some tables into staff vs. regular user tables
Browse files Browse the repository at this point in the history
Also add tests for the tables and for the views using those tables
(WorkspaceList).
  • Loading branch information
amstilp committed Dec 2, 2024
1 parent 8522653 commit 0891a0f
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 38 deletions.
6 changes: 3 additions & 3 deletions gregor_django/gregor_anvil/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
43 changes: 35 additions & 8 deletions gregor_django/gregor_anvil/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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."""

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
131 changes: 113 additions & 18 deletions gregor_django/gregor_anvil/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand 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())
Expand 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())
Expand 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())
Expand 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())
Expand 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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Loading

0 comments on commit 0891a0f

Please sign in to comment.