Skip to content

Commit

Permalink
Merge branch 'main' into feature/cdsa-invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
amstilp authored Sep 29, 2023
2 parents 7c44629 + 6b16c6b commit 6f630c4
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 47 deletions.
13 changes: 12 additions & 1 deletion primed/cdsa/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Meta:
"date_signed",
"number_accessors",
)
order_by = ("cc_id",)


class MemberAgreementTable(tables.Table):
Expand Down Expand Up @@ -104,6 +105,7 @@ class Meta:
"signed_agreement__date_signed",
"number_accessors",
)
order_by = ("signed_agreement__cc_id",)


class DataAffiliateAgreementTable(tables.Table):
Expand Down Expand Up @@ -137,6 +139,7 @@ class Meta:
"signed_agreement__date_signed",
"number_accessors",
)
order_by = ("signed_agreement__cc_id",)


class NonDataAffiliateAgreementTable(tables.Table):
Expand Down Expand Up @@ -167,6 +170,7 @@ class Meta:
"signed_agreement__date_signed",
"number_accessors",
)
order_by = ("signed_agreement__cc_id",)


class RepresentativeRecordsTable(tables.Table):
Expand All @@ -188,6 +192,7 @@ class Meta:
"agreement_type",
"version",
)
order_by = ("representative__name",)

def render_signing_group(self, record):
if hasattr(record, "memberagreement"):
Expand All @@ -207,13 +212,16 @@ class StudyRecordsTable(tables.Table):
signed_agreement__representative__name = tables.Column(
verbose_name="Representative"
)
# This will only order properly if the order_by value is a column in the table.
study__short_name = tables.Column(verbose_name="Study")

class Meta:
model = models.DataAffiliateAgreement
fields = (
"study",
"study__short_name",
"signed_agreement__representative__name",
)
order_by = ("study__short_name",)


class UserAccessRecordsTable(tables.Table):
Expand All @@ -235,6 +243,7 @@ class Meta:
"group__signedagreement__signing_institution",
"group__signedagreement__representative__name",
)
order_by = ("account__user__name",)

def render_signing_group(self, record):
if hasattr(record.group.signedagreement, "memberagreement"):
Expand Down Expand Up @@ -274,6 +283,7 @@ class Meta:
"workspace__created",
"date_shared",
)
order_by = ("workspace__name",)

def render_date_shared(self, record):
try:
Expand Down Expand Up @@ -310,3 +320,4 @@ class Meta:
"cdsaworkspace__data_use_permission__abbreviation",
"cdsaworkspace__data_use_modifiers",
)
order_by = ("name",)
91 changes: 91 additions & 0 deletions primed/cdsa/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.test import TestCase

from primed.primed_anvil.tests.factories import StudyFactory, StudySiteFactory
from primed.users.tests.factories import UserFactory

from .. import models, tables
from . import factories
Expand Down Expand Up @@ -69,6 +70,14 @@ def test_number_accessors(self):
self.assertEqual(table.rows[1].get_cell("number_accessors"), 1)
self.assertEqual(table.rows[2].get_cell("number_accessors"), 2)

def test_ordering(self):
"""Instances are ordered alphabetically by cc_id."""
instance_1 = factories.MemberAgreementFactory.create(signed_agreement__cc_id=2)
instance_2 = factories.MemberAgreementFactory.create(signed_agreement__cc_id=1)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2.signed_agreement)
self.assertEqual(table.data[1], instance_1.signed_agreement)


class MemberAgreementTableTest(TestCase):
model = models.MemberAgreement
Expand Down Expand Up @@ -105,6 +114,14 @@ def test_number_accessors(self):
self.assertEqual(table.rows[1].get_cell("number_accessors"), 1)
self.assertEqual(table.rows[2].get_cell("number_accessors"), 2)

def test_ordering(self):
"""Instances are ordered alphabetically by cc_id."""
instance_1 = self.model_factory.create(signed_agreement__cc_id=2)
instance_2 = self.model_factory.create(signed_agreement__cc_id=1)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2)
self.assertEqual(table.data[1], instance_1)


class DataAffiliateAgreementTableTest(TestCase):
model = models.DataAffiliateAgreement
Expand Down Expand Up @@ -141,6 +158,14 @@ def test_number_accessors(self):
self.assertEqual(table.rows[1].get_cell("number_accessors"), 1)
self.assertEqual(table.rows[2].get_cell("number_accessors"), 2)

def test_ordering(self):
"""Instances are ordered alphabetically by cc_id."""
instance_1 = self.model_factory.create(signed_agreement__cc_id=2)
instance_2 = self.model_factory.create(signed_agreement__cc_id=1)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2)
self.assertEqual(table.data[1], instance_1)


class NonDataAffiliateAgreementTableTest(TestCase):
model = models.NonDataAffiliateAgreement
Expand Down Expand Up @@ -177,6 +202,14 @@ def test_number_accessors(self):
self.assertEqual(table.rows[1].get_cell("number_accessors"), 1)
self.assertEqual(table.rows[2].get_cell("number_accessors"), 2)

def test_ordering(self):
"""Instances are ordered alphabetically by cc_id."""
instance_1 = self.model_factory.create(signed_agreement__cc_id=2)
instance_2 = self.model_factory.create(signed_agreement__cc_id=1)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2)
self.assertEqual(table.data[1], instance_1)


class RepresentativeRecordsTableTest(TestCase):
"""Tests for the RepresentativeRecordsTable class."""
Expand Down Expand Up @@ -223,6 +256,18 @@ def test_render_signing_group(self):
record = factories.SignedAgreementFactory()
self.assertIsNone(table.render_signing_group(record))

def test_ordering(self):
"""Instances are ordered alphabetically by representative name."""
instance_1 = factories.MemberAgreementFactory.create(
signed_agreement__representative__name="zzz"
)
instance_2 = factories.MemberAgreementFactory.create(
signed_agreement__representative__name="aaa"
)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2.signed_agreement)
self.assertEqual(table.data[1], instance_1.signed_agreement)


class StudyRecordsTableTest(TestCase):
"""Tests for the StudyRecordsTable class."""
Expand All @@ -245,6 +290,14 @@ def test_row_count_with_two_objects(self):
table = self.table_class(self.model.objects.all())
self.assertEqual(len(table.rows), 2)

def test_ordering(self):
"""Instances are ordered alphabetically by study short name."""
instance_1 = self.model_factory.create(study__short_name="zzz")
instance_2 = self.model_factory.create(study__short_name="aaa")
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2)
self.assertEqual(table.data[1], instance_1)


class UserAccessRecordsTableTest(TestCase):
"""Tests for the UserAccessRecordsTable class."""
Expand Down Expand Up @@ -328,6 +381,23 @@ def test_render_signing_group(self):
record = GroupAccountMembershipFactory.create(group__signedagreement=agreement)
self.assertIsNone(table.render_signing_group(record))

def test_ordering(self):
"""Instances are ordered alphabetically by user name."""
agreement = factories.MemberAgreementFactory.create()
user_1 = UserFactory.create(name="zzz")
instance_1 = GroupAccountMembershipFactory.create(
group__signedagreement=agreement.signed_agreement,
account__user=user_1,
)
user_2 = UserFactory.create(name="aaa")
instance_2 = GroupAccountMembershipFactory.create(
group__signedagreement=agreement.signed_agreement,
account__user=user_2,
)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2)
self.assertEqual(table.data[1], instance_1)


class CDSAWorkspaceRecordsTableTest(TestCase):
"""Tests for the CDSAWorkspaceRecordsTable class."""
Expand Down Expand Up @@ -363,6 +433,19 @@ def test_render_date_shared(self):
)
self.assertNotEqual(table.render_date_shared(cdsa_workspace), "—")

def test_ordering(self):
"""Instances are ordered alphabetically by user name."""
agreement = factories.DataAffiliateAgreementFactory.create()
instance_1 = factories.CDSAWorkspaceFactory.create(
study=agreement.study, workspace__name="zzz"
)
instance_2 = factories.CDSAWorkspaceFactory.create(
study=agreement.study, workspace__name="aaa"
)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2)
self.assertEqual(table.data[1], instance_1)


class CDSAWorkspaceTableTest(TestCase):
"""Tests for the CDSAWorkspaceTable class."""
Expand Down Expand Up @@ -412,3 +495,11 @@ def test_render_is_shared_shared_with_different_group(self):
)
table = self.table_class(self.model.objects.all())
self.assertEqual("", table.rows[0].get_cell_value("is_shared"))

def test_ordering(self):
"""Instances are ordered alphabetically by user name."""
instance_1 = factories.CDSAWorkspaceFactory.create(workspace__name="zzz")
instance_2 = factories.CDSAWorkspaceFactory.create(workspace__name="aaa")
table = self.table_class(self.model.objects.all())
self.assertEqual(table.data[0], instance_2.workspace)
self.assertEqual(table.data[1], instance_1.workspace)
2 changes: 1 addition & 1 deletion primed/dbgap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Meta:

def __str__(self):
"""String method."""
return "{} - {}".format(self.dbgap_application, self.created)
return "{}".format(self.created)

def clean(self):
"""Perform custom model cleaning.
Expand Down
Loading

0 comments on commit 6f630c4

Please sign in to comment.