def test_send_all_samples_sends_each_samples_with_project_release_date(self): # Given self.submitter.send_sample = MagicMock(return_value='UPDATED') test_date = datetime.now().isoformat() project_attributes = { 'releaseDate': test_date } project_attributes = make_ingest_entity('projects', random_id(), random_uuid(), project_attributes) self.submission.map_ingest_entity(project_attributes) biomaterials = self.map_random_biomaterials(self.submission, 5) calls = [] call_count = 0 expected_result = {'UPDATED': []} for entity in biomaterials: call_count += 1 calls.append(call(entity, test_date)) expected_result['UPDATED'].append(entity) # When result = self.submitter.send_all_samples(self.submission) # Then self.submitter.send_sample.assert_has_calls(calls, any_order=True) self.assertEqual(call_count, self.submitter.send_sample.call_count) self.assertDictEqual(expected_result, result)
def test_submit_sample_return_creation(self): # Given self.biosamples.send_sample = MagicMock(return_value={'accession': 'SAMEA1234567'}) test_case = self.submission.map_ingest_entity(make_ingest_entity('biomaterials', random_id(), random_uuid())) # When result = self.submitter.send_sample(test_case) # Then self.assertEqual('CREATED', result)
def setUp(self) -> None: # Given self.test_type = random_id() self.test_id = random_id() self.test_uuid = random_uuid() self.test_case = make_ingest_entity(self.test_type, self.test_id, self.test_uuid) self.submission = HcaSubmission() # When self.test_entity = self.submission.map_ingest_entity(self.test_case)
def map_random_biomaterials(submission: HcaSubmission, entity_count: int) -> List[Entity]: biomaterials = [] for i in range(0, entity_count): biomaterials.append( submission.map_ingest_entity( make_ingest_entity('biomaterials', random_id(), random_uuid()) ) ) return biomaterials
def test_duplication_entity_with_differing_content_is_ignored(self): # Given ignored_uuid = random_uuid() duplicate_test_case = make_ingest_entity(self.test_type, self.test_id, ignored_uuid) # When duplicate_entity = self.submission.map_ingest_entity(duplicate_test_case) # Then self.assertEqual(self.test_entity, duplicate_entity) self.assertEqual(self.test_uuid, self.test_entity.attributes['uuid']['uuid']) self.assertNotEqual(ignored_uuid, self.test_entity.attributes['uuid']['uuid'])
def test_submit_sample_return_error(self): # Given error_msg = f'TestCaseError{random_id(3)}' self.biosamples.send_sample = MagicMock(side_effect=Exception(error_msg)) test_case = self.submission.map_ingest_entity( make_ingest_entity('biomaterials', random_id(), random_uuid())) # When result = self.submitter.send_sample(test_case) # Then self.assertEqual('ERRORED', result) self.assertDictEqual(test_case.get_errors(), {'content.biomaterial_core.biosamples_accession': [f'BioSamples Error: {error_msg}']})
def test_submit_sample_converts_and_sends_sample(self): # Given test_case = self.submission.map_ingest_entity( make_ingest_entity('biomaterials', random_id(), random_uuid()) ) # When result = self.submitter.send_sample(test_case) # Then self.converter.convert.assert_called_once_with(test_case.attributes, release_date=None, accession=None) self.biosamples.send_sample.assert_called_once_with(self.empty_sample) self.assertEqual('UPDATED', result)
def map_random_entities( submission: HcaSubmission, entity_count: int, entity_type: str = None ): entity_list = [] for i in range(0, entity_count): entity_list.append( submission.map_ingest_entity( make_ingest_entity( entity_type if entity_type else random_id(), random_id(), random_uuid() ) ) ) return entity_list