def test_maps_response(self): """We map the response to a RWSSubjects instance""" response_content = """ <ODM FileType="Snapshot" FileOID="770f1758-db33-4ab2-af72-38db863734aa" CreationDateTime="2013-04-08T14:08:06.875-00:00" ODMVersion="1.3"> <ClinicalData StudyOID="Fixitol(Dev)" MetaDataVersionOID="1111"> <SubjectData SubjectKey="000001"> <SiteRef LocationOID="BP001"/> </SubjectData> </ClinicalData> <ClinicalData StudyOID="Fixitol(Dev)" MetaDataVersionOID="1111"> <SubjectData SubjectKey="1111"> <SiteRef LocationOID="335566"/> </SubjectData> </ClinicalData> </ODM> """ request = StudySubjectsRequest("Fixitol", "Dev") req = mock.Mock(requests.Request, text=response_content) response = request.result(req) self.assertTrue(isinstance(response, RWSSubjects)) for subject in response: self.assertTrue(isinstance(subject, RWSSubjectListItem)) self.assertTrue(subject.subject_name in ['000001', "1111"])
def test_request_uuid_type(self): """ Confirm we request the UUID Subject Key Type """ request = StudySubjectsRequest(self.project_name, self.environment, subject_key_type="SubjectUUID") self.assertTrue("subjectKeyType=SubjectUUID" in request.url_path())
def test_request_with_status(self): """ Confirm we request the status when asked to """ request = StudySubjectsRequest(self.project_name, self.environment, status=True) self.assertTrue("status=all" in request.url_path())
def test_subj_key_type_is_valid(self): """ Confirm that only valid SubjectKeyTypes are accepted """ with self.assertRaises(ValueError) as err: request = StudySubjectsRequest(self.project_name, self.environment, subject_key_type="AnApple") self.assertEqual(str(err.exception), "SubjectKeyType AnApple is not a valid value") request = StudySubjectsRequest(self.project_name, self.environment, subject_key_type="SubjectName") self.assertEqual(self.project_name, request.project_name)
def get_rave_subjects(): """ Gets a list of Patients registered :return: """ client = RWSConnection(domain=RAVE_URL, username=RAVE_USER, password=RAVE_PASSWORD) subjects = client.send_request( StudySubjectsRequest(STUDY, ENV, subject_key_type='SubjectUUID')) return subjects
def test_request_with_include(self): """ Confirm we request the status when asked to """ request = StudySubjectsRequest(self.project_name, self.environment, include="inactive") self.assertTrue("include=inactive" in request.url_path()) request = StudySubjectsRequest(self.project_name, self.environment, include="inactiveAndDeleted") self.assertTrue("include=inactiveAndDeleted" in request.url_path()) request = StudySubjectsRequest(self.project_name, self.environment, include="deleted") self.assertTrue("include=deleted" in request.url_path()) with self.assertRaises(ValueError) as err: request = StudySubjectsRequest(self.project_name, self.environment, include="kitchen_sink") self.assertEqual("If provided, included must be one of inactive,deleted,inactiveAndDeleted", err.exception.message)
def test_request_without_type(self): """ Confirm we request the UUID Subject Key Type """ request = StudySubjectsRequest(self.project_name, self.environment) self.assertFalse("subjectKeyType" in request.url_path())
def test_request_with_include(self): """ Confirm we request the status when asked to """ request = StudySubjectsRequest(self.project_name, self.environment, include="inactive") self.assertTrue("include=inactive" in request.url_path()) request = StudySubjectsRequest(self.project_name, self.environment, include="inactiveAndDeleted") self.assertTrue("include=inactiveAndDeleted" in request.url_path()) request = StudySubjectsRequest(self.project_name, self.environment, include="deleted") self.assertTrue("include=deleted" in request.url_path()) with self.assertRaises(ValueError) as err: request = StudySubjectsRequest(self.project_name, self.environment, include="kitchen_sink") self.assertEqual( "If provided, included must be one of inactive,deleted,inactiveAndDeleted", str(err.exception))
def get_subject_data(study_list=[]): for final in study_list: subject_data = rws_connection.send_request( StudySubjectsRequest(project_name=final, environment_name='Prod'))