Skip to content

Commit

Permalink
Merge pull request #384 from UW-GAC/feature/cdsa-status-replaced
Browse files Browse the repository at this point in the history
Add "replaced" status for CDSAs
  • Loading branch information
amstilp authored Jan 20, 2024
2 parents 6975fc0 + 6b8d3ef commit 6a06dab
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 17 deletions.
46 changes: 46 additions & 0 deletions primed/cdsa/migrations/0011_signedagreement_add_replaced_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 4.2.8 on 2024-01-18 23:49

from django.db import migrations
import model_utils.fields


class Migration(migrations.Migration):

dependencies = [
("cdsa", "0010_alter_historicalsignedagreement_status_and_more"),
]

operations = [
migrations.AlterField(
model_name="historicalsignedagreement",
name="status",
field=model_utils.fields.StatusField(
choices=[
("active", "Active"),
("withdrawn", "Withdrawn"),
("lapsed", "Lapsed"),
("replaced", "Replaced"),
],
default="active",
max_length=100,
no_check_for_status=True,
verbose_name="status",
),
),
migrations.AlterField(
model_name="signedagreement",
name="status",
field=model_utils.fields.StatusField(
choices=[
("active", "Active"),
("withdrawn", "Withdrawn"),
("lapsed", "Lapsed"),
("replaced", "Replaced"),
],
default="active",
max_length=100,
no_check_for_status=True,
verbose_name="status",
),
),
]
7 changes: 5 additions & 2 deletions primed/cdsa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ class SignedAgreementStatusMixin:

class StatusChoices(models.TextChoices):
ACTIVE = "active", "Active"
"""SignedAgreements that are currently active."""
"""SignedAgreements that are currently active.""" # pragma: no cover

WITHDRAWN = "withdrawn", "Withdrawn"
"""SignedAgreements that have been withdrawn for some reason (e.g., PI changed institution,
study no longer wanted to participate.)"""

LAPSED = "lapsed", "Lapsed"
"""SignedAgreements from a AgreementMajorVersion that is no longer valid."""
"""SignedAgreements from a AgreementMajorVersion that is no longer valid.""" # pragma: no cover

REPLACED = "replaced", "Replaced"
"""SignedAgreements that have been replaced by a newer version.""" # pragma: no cover

STATUS = StatusChoices.choices

Expand Down
20 changes: 5 additions & 15 deletions primed/cdsa/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,6 @@ def test_get_absolute_url(self):
instance.signed_agreement.get_absolute_url(), instance.get_absolute_url()
)

def test_statuses(self):
"""All allowed statuses."""
instance = factories.SignedAgreementFactory.create(
status=models.SignedAgreement.StatusChoices.ACTIVE
)
instance.full_clean()
instance = factories.SignedAgreementFactory.create(
status=models.SignedAgreement.StatusChoices.WITHDRAWN
)
instance.full_clean()
instance = factories.SignedAgreementFactory.create(
status=models.SignedAgreement.StatusChoices.LAPSED
)
instance.full_clean()

def test_member_choices(self):
"""Can create instances with all of the member choices."""
instance = factories.SignedAgreementFactory.create(
Expand Down Expand Up @@ -319,6 +304,11 @@ def test_status_field(self):
)
self.assertEqual(instance.status, instance.StatusChoices.LAPSED)
instance.full_clean()
instance = factories.SignedAgreementFactory.create(
status=models.SignedAgreement.StatusChoices.REPLACED
)
self.assertEqual(instance.status, instance.StatusChoices.REPLACED)
instance.full_clean()

# not allowed
instance = factories.SignedAgreementFactory.create(status="foo")
Expand Down
29 changes: 29 additions & 0 deletions primed/cdsa/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ def test_only_sets_active_signed_agreements_to_lapsed(self):
version__major_version=instance,
status=models.SignedAgreement.StatusChoices.LAPSED,
)
replaced_agreement = factories.SignedAgreementFactory.create(
version__major_version=instance,
status=models.SignedAgreement.StatusChoices.REPLACED,
)
self.client.force_login(self.user)
response = self.client.post(self.get_url(instance.version), {})
self.assertEqual(response.status_code, 302)
Expand All @@ -559,6 +563,10 @@ def test_only_sets_active_signed_agreements_to_lapsed(self):
self.assertEqual(
withdrawn_agreement.status, models.SignedAgreement.StatusChoices.WITHDRAWN
)
replaced_agreement.refresh_from_db()
self.assertEqual(
replaced_agreement.status, models.SignedAgreement.StatusChoices.REPLACED
)

def test_only_sets_associated_signed_agreements_to_lapsed(self):
"""Does not set SignedAgreements associated with a different version to LAPSED."""
Expand Down Expand Up @@ -5293,6 +5301,9 @@ def test_only_includes_active_agreements(self):
withdrawn_agreement = factories.MemberAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.WITHDRAWN
)
replaced_agreement = factories.MemberAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.REPLACED
)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
Expand All @@ -5301,6 +5312,7 @@ def test_only_includes_active_agreements(self):
self.assertIn(active_agreement.signed_agreement, table.data)
self.assertNotIn(lapsed_agreement.signed_agreement, table.data)
self.assertNotIn(withdrawn_agreement.signed_agreement, table.data)
self.assertNotIn(replaced_agreement.signed_agreement, table.data)


class SignedAgreementAuditTest(TestCase):
Expand Down Expand Up @@ -5758,6 +5770,9 @@ def test_only_includes_active_agreements(self):
withdrawn_agreement = factories.DataAffiliateAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.WITHDRAWN
)
replaced_agreement = factories.DataAffiliateAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.REPLACED
)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
Expand All @@ -5766,6 +5781,7 @@ def test_only_includes_active_agreements(self):
self.assertIn(active_agreement, table.data)
self.assertNotIn(lapsed_agreement, table.data)
self.assertNotIn(withdrawn_agreement, table.data)
self.assertNotIn(replaced_agreement, table.data)


class UserAccessRecordsList(TestCase):
Expand Down Expand Up @@ -5943,6 +5959,12 @@ def test_only_includes_active_agreements(self):
withdrawn_member = GroupAccountMembershipFactory.create(
group=withdrawn_agreement.signed_agreement.anvil_access_group
)
replaced_agreement = factories.MemberAgreementFactory.create(
signed_agreement__status=models.SignedAgreement.StatusChoices.REPLACED
)
replaced_member = GroupAccountMembershipFactory.create(
group=replaced_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)
Expand All @@ -5951,6 +5973,7 @@ def test_only_includes_active_agreements(self):
self.assertIn(active_member, table.data)
self.assertNotIn(lapsed_member, table.data)
self.assertNotIn(withdrawn_member, table.data)
self.assertNotIn(replaced_member, table.data)


class CDSAWorkspaceRecordsList(TestCase):
Expand Down Expand Up @@ -6021,6 +6044,11 @@ def test_only_includes_workspaces_with_active_agreements(self):
study=withdrawn_workspace.study,
signed_agreement__status=models.SignedAgreement.StatusChoices.WITHDRAWN,
)
replaced_workspace = factories.CDSAWorkspaceFactory.create()
factories.DataAffiliateAgreementFactory.create(
study=replaced_workspace.study,
signed_agreement__status=models.SignedAgreement.StatusChoices.REPLACED,
)
self.client.force_login(self.user)
response = self.client.get(self.get_url())
self.assertIn("table", response.context_data)
Expand All @@ -6029,6 +6057,7 @@ def test_only_includes_workspaces_with_active_agreements(self):
self.assertIn(active_workspace, table.data)
self.assertNotIn(lapsed_workspace, table.data)
self.assertNotIn(withdrawn_workspace, table.data)
self.assertNotIn(replaced_workspace, table.data)


class CDSAWorkspaceDetailTest(TestCase):
Expand Down

0 comments on commit 6a06dab

Please sign in to comment.