diff --git a/primed/dbgap/models.py b/primed/dbgap/models.py index 1a17ef7f..299a2424 100644 --- a/primed/dbgap/models.py +++ b/primed/dbgap/models.py @@ -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: @@ -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 diff --git a/primed/dbgap/tests/test_models.py b/primed/dbgap/tests/test_models.py index c42515d5..bdf1f101 100644 --- a/primed/dbgap/tests/test_models.py +++ b/primed/dbgap/tests/test_models.py @@ -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, @@ -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, @@ -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() @@ -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, @@ -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( @@ -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(