Skip to content

Commit

Permalink
Merge pull request #159 from UW-GAC/main
Browse files Browse the repository at this point in the history
Deploy to stage
  • Loading branch information
amstilp authored Mar 15, 2023
2 parents 6969ee3 + 1eb21d6 commit ddffb02
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
8 changes: 4 additions & 4 deletions primed/dbgap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def get_data_access_requests(self, most_recent=False):
"""Get a list of data access requests associated with this dbGaPWorkspace."""
qs = dbGaPDataAccessRequest.objects.filter(
dbgap_phs=self.dbgap_study_accession.dbgap_phs,
original_version=self.dbgap_version,
original_participant_set=self.dbgap_participant_set,
original_version__lte=self.dbgap_version,
original_participant_set__lte=self.dbgap_participant_set,
dbgap_consent_code=self.dbgap_consent_code,
)
if most_recent:
Expand Down Expand Up @@ -493,8 +493,8 @@ def get_dbgap_workspace(self):
# We may need to modify this to match the DAR version *or greater*, and DAR participant set *or larger*.
study_accession = dbGaPStudyAccession.objects.get(dbgap_phs=self.dbgap_phs)
dbgap_workspace = study_accession.dbgapworkspace_set.get(
dbgap_version=self.original_version,
dbgap_participant_set=self.original_participant_set,
dbgap_version__gte=self.original_version,
dbgap_participant_set__gte=self.original_participant_set,
dbgap_consent_code=self.dbgap_consent_code,
)
return dbgap_workspace
Expand Down
66 changes: 59 additions & 7 deletions primed/dbgap/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ def test_get_data_access_requests_different_phs(self):
)
self.assertEqual(len(workspace.get_data_access_requests()), 0)

def test_get_data_access_requests_different_version(self):
"""Does not return a DAR where version doesn't match."""
def test_get_data_access_requests_larger_version(self):
"""Does not return a DAR that has a later version than this workspace."""
workspace = factories.dbGaPWorkspaceFactory.create()
factories.dbGaPDataAccessRequestFactory.create(
dbgap_phs=workspace.dbgap_study_accession.dbgap_phs,
Expand All @@ -362,8 +362,21 @@ def test_get_data_access_requests_different_version(self):
)
self.assertEqual(len(workspace.get_data_access_requests()), 0)

def test_get_data_access_requests_different_participant_set(self):
"""Does not return a DAR where participant set doesn't match."""
def test_get_data_access_requests_smaller_version(self):
"""Does return a DAR that has an earlier version than this workspace."""
workspace = factories.dbGaPWorkspaceFactory.create(dbgap_version=2)
dar = factories.dbGaPDataAccessRequestFactory.create(
dbgap_phs=workspace.dbgap_study_accession.dbgap_phs,
original_version=1,
original_participant_set=workspace.dbgap_participant_set,
dbgap_consent_code=workspace.dbgap_consent_code,
)
results = workspace.get_data_access_requests()
self.assertEqual(len(results), 1)
self.assertIn(dar, results)

def test_get_data_access_requests_larger_participant_set(self):
"""Does not return a DAR where participant set is larger than the workspace."""
workspace = factories.dbGaPWorkspaceFactory.create()
factories.dbGaPDataAccessRequestFactory.create(
dbgap_phs=workspace.dbgap_study_accession.dbgap_phs,
Expand All @@ -373,6 +386,21 @@ def test_get_data_access_requests_different_participant_set(self):
)
self.assertEqual(len(workspace.get_data_access_requests()), 0)

def test_get_data_access_requests_smaller_participant_set(self):
"""Does return a DAR where participant set is smaller than the workspace."""
workspace = factories.dbGaPWorkspaceFactory.create(
dbgap_version=2, dbgap_participant_set=2
)
dar = factories.dbGaPDataAccessRequestFactory.create(
dbgap_phs=workspace.dbgap_study_accession.dbgap_phs,
original_version=1,
original_participant_set=1,
dbgap_consent_code=workspace.dbgap_consent_code,
)
results = workspace.get_data_access_requests()
self.assertEqual(len(results), 1)
self.assertIn(dar, results)

def test_get_data_access_requests_different_consent_code(self):
"""Does not return a DAR where consent code doesn't match."""
workspace = factories.dbGaPWorkspaceFactory.create()
Expand Down Expand Up @@ -1487,8 +1515,8 @@ def test_get_dbgap_workspace_one_match(self):
)
self.assertEqual(dar.get_dbgap_workspace(), workspace)

def test_get_dbgap_workspace_different_version(self):
"""Raises ObjectNotFound for workspace with the same phs but different version."""
def test_get_dbgap_workspace_smaller_version(self):
"""Raises ObjectNotFound for workspace with the same phs but a smaller version."""
workspace = factories.dbGaPWorkspaceFactory.create(dbgap_version=1)
dar = factories.dbGaPDataAccessRequestFactory.create(
dbgap_phs=workspace.dbgap_study_accession.dbgap_phs,
Expand All @@ -1499,7 +1527,18 @@ def test_get_dbgap_workspace_different_version(self):
with self.assertRaises(models.dbGaPWorkspace.DoesNotExist):
dar.get_dbgap_workspace()

def test_get_dbgap_workspace_different_participant_set(self):
def test_get_dbgap_workspace_larger_version(self):
"""Raises ObjectNotFound for workspace with the same phs but a larger version."""
workspace = factories.dbGaPWorkspaceFactory.create(dbgap_version=3)
dar = factories.dbGaPDataAccessRequestFactory.create(
dbgap_phs=workspace.dbgap_study_accession.dbgap_phs,
original_version=2,
original_participant_set=workspace.dbgap_participant_set,
dbgap_consent_code=workspace.dbgap_consent_code,
)
self.assertEqual(dar.get_dbgap_workspace(), workspace)

def test_get_dbgap_workspace_smaller_participant_set(self):
"""Raises ObjectNotFound for workspace with the same phs/version but different participant set."""
workspace = factories.dbGaPWorkspaceFactory.create(dbgap_participant_set=1)
dar = factories.dbGaPDataAccessRequestFactory.create(
Expand All @@ -1511,6 +1550,19 @@ def test_get_dbgap_workspace_different_participant_set(self):
with self.assertRaises(models.dbGaPWorkspace.DoesNotExist):
dar.get_dbgap_workspace()

def test_get_dbgap_workspace_larger_participant_set(self):
"""Finds a matching workspace with a larger version and participant set."""
workspace = factories.dbGaPWorkspaceFactory.create(
dbgap_version=2, dbgap_participant_set=2
)
dar = factories.dbGaPDataAccessRequestFactory.create(
dbgap_phs=workspace.dbgap_study_accession.dbgap_phs,
original_version=1,
original_participant_set=1,
dbgap_consent_code=workspace.dbgap_consent_code,
)
self.assertEqual(dar.get_dbgap_workspace(), workspace)

def test_get_dbgap_workspace_different_dbgap_study_accession(self):
"""Raises ObjectNotFound for workspace with the same phs/version but different phs."""
workspace = factories.dbGaPWorkspaceFactory.create(
Expand Down

0 comments on commit ddffb02

Please sign in to comment.