Skip to content

Commit

Permalink
Update CDSA records tables to only show active records
Browse files Browse the repository at this point in the history
Only records associated with an active SignedAgreement are shown
in the tables.
  • Loading branch information
amstilp committed Sep 22, 2023
1 parent 5917a0e commit 5e16d6a
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 8 deletions.
19 changes: 15 additions & 4 deletions primed/cdsa/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@

def get_representative_records_table():
"""Return the queryset for representative records."""
qs = models.SignedAgreement.objects.all()
qs = models.SignedAgreement.active.all()
return tables.RepresentativeRecordsTable(qs)


def get_study_records_table():
"""Return the queryset for study records."""
qs = models.DataAffiliateAgreement.objects.filter(signed_agreement__is_primary=True)
qs = models.DataAffiliateAgreement.objects.filter(
signed_agreement__status=models.SignedAgreement.StatusChoices.ACTIVE,
signed_agreement__is_primary=True,
)
return tables.StudyRecordsTable(qs)


def get_user_access_records_table():
"""Return the queryset for user access records."""
qs = GroupAccountMembership.objects.filter(group__signedagreement__isnull=False)
qs = GroupAccountMembership.objects.filter(
group__signedagreement__status=models.SignedAgreement.StatusChoices.ACTIVE,
group__signedagreement__isnull=False,
)
return tables.UserAccessRecordsTable(qs)


def get_cdsa_workspace_records_table():
"""Return the queryset for workspace records."""
qs = models.CDSAWorkspace.objects.all()
active_data_affiliates = models.DataAffiliateAgreement.objects.filter(
signed_agreement__status=models.SignedAgreement.StatusChoices.ACTIVE,
)
qs = models.CDSAWorkspace.objects.filter(
study__dataaffiliateagreement__in=active_data_affiliates,
)
return tables.CDSAWorkspaceRecordsTable(qs)
3 changes: 2 additions & 1 deletion primed/cdsa/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_cdsa_workspace_records_zero(self):
self.assertEqual(len(lines), 1)

def test_cdsa_workspace_records_one(self):
factories.CDSAWorkspaceFactory.create()
agreement = factories.DataAffiliateAgreementFactory.create()
factories.CDSAWorkspaceFactory.create(study=agreement.study)
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "workspace_records.tsv")) as f:
Expand Down
94 changes: 91 additions & 3 deletions primed/cdsa/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4593,6 +4593,23 @@ def test_table_three_rows(self):
self.assertIn("table", response.context_data)
self.assertEqual(len(response.context_data["table"].rows), 3)

def test_only_includes_active_agreements(self):
active_agreement = factories.MemberAgreementFactory.create()
lapsed_agreement = factories.MemberAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.LAPSED
)
withdrawn_agreement = factories.MemberAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.WITHDRAWN
)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
table = response.context_data["table"]
self.assertEqual(len(table.rows), 1)
self.assertIn(active_agreement.signed_agreement, table.data)
self.assertNotIn(lapsed_agreement.signed_agreement, table.data)
self.assertNotIn(withdrawn_agreement.signed_agreement, table.data)


class SignedAgreementAuditTest(TestCase):
"""Tests for the SignedAgreementAudit view."""
Expand Down Expand Up @@ -5041,6 +5058,23 @@ def test_only_shows_primary_data_affiliate_records(self):
self.assertIn(primary_agreement, table.data)
self.assertNotIn(component_agreement, table.data)

def test_only_includes_active_agreements(self):
active_agreement = factories.DataAffiliateAgreementFactory.create()
lapsed_agreement = factories.DataAffiliateAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.LAPSED
)
withdrawn_agreement = factories.DataAffiliateAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.WITHDRAWN
)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
table = response.context_data["table"]
self.assertEqual(len(table.rows), 1)
self.assertIn(active_agreement, table.data)
self.assertNotIn(lapsed_agreement, table.data)
self.assertNotIn(withdrawn_agreement, table.data)


class UserAccessRecordsList(TestCase):
"""Tests for the StudyRecordsList view."""
Expand Down Expand Up @@ -5200,6 +5234,32 @@ def test_does_not_show_other_group_members(self):
table = response.context_data["table"]
self.assertEqual(len(table.rows), 0)

def test_only_includes_active_agreements(self):
active_agreement = factories.MemberAgreementFactory.create()
active_member = GroupAccountMembershipFactory.create(
group=active_agreement.signed_agreement.anvil_access_group
)
lapsed_agreement = factories.MemberAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.LAPSED
)
lapsed_member = GroupAccountMembershipFactory.create(
group=lapsed_agreement.signed_agreement.anvil_access_group
)
withdrawn_agreement = factories.MemberAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.WITHDRAWN
)
withdrawn_member = GroupAccountMembershipFactory.create(
group=withdrawn_agreement.signed_agreement.anvil_access_group
)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
table = response.context_data["table"]
self.assertEqual(len(table.rows), 1)
self.assertIn(active_member, table.data)
self.assertNotIn(lapsed_member, table.data)
self.assertNotIn(withdrawn_member, table.data)


class CDSAWorkspaceRecordsList(TestCase):
"""Tests for the CDSAWorkspaceRecords view."""
Expand Down Expand Up @@ -5242,13 +5302,41 @@ def test_table_no_rows(self):
self.assertIn("table", response.context_data)
self.assertEqual(len(response.context_data["table"].rows), 0)

def test_table_three_rows(self):
def test_table_two_rows(self):
"""Three rows are shown if there are three CDSAWorkspaces objects."""
factories.CDSAWorkspaceFactory.create_batch(3)
active_workspace_1 = factories.CDSAWorkspaceFactory.create()
factories.DataAffiliateAgreementFactory.create(study=active_workspace_1.study)
active_workspace_2 = factories.CDSAWorkspaceFactory.create()
factories.DataAffiliateAgreementFactory.create(study=active_workspace_2.study)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
self.assertEqual(len(response.context_data["table"].rows), 3)
table = response.context_data["table"]
self.assertEqual(len(table.rows), 2)
self.assertIn(active_workspace_1, table.data)
self.assertIn(active_workspace_2, table.data)

def test_only_includes_workspaces_with_active_agreements(self):
active_workspace = factories.CDSAWorkspaceFactory.create()
factories.DataAffiliateAgreementFactory.create(study=active_workspace.study)
lapsed_workspace = factories.CDSAWorkspaceFactory.create()
factories.DataAffiliateAgreementFactory.create(
study=lapsed_workspace.study,
signed_agreement__status=models.SignedAgreement.StatusChoices.LAPSED,
)
withdrawn_workspace = factories.CDSAWorkspaceFactory.create()
factories.DataAffiliateAgreementFactory.create(
study=withdrawn_workspace.study,
signed_agreement__status=models.SignedAgreement.StatusChoices.WITHDRAWN,
)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
table = response.context_data["table"]
self.assertEqual(len(table.rows), 1)
self.assertIn(active_workspace, table.data)
self.assertNotIn(lapsed_workspace, table.data)
self.assertNotIn(withdrawn_workspace, table.data)


class CDSAWorkspaceDetailTest(TestCase):
Expand Down

0 comments on commit 5e16d6a

Please sign in to comment.