def test_ds_parent_create(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: parent_samp = openapi_client.DerivativeSample(None) parent_created = api_instance.create_derivative_sample(parent_samp) samp = openapi_client.DerivativeSample(None) samp.parent_derivative_sample_id = parent_created.derivative_sample_id created = api_instance.create_derivative_sample(samp) if not api_factory.is_authorized(None): pytest.fail( 'Unauthorized call to create_derivative_sample succeeded') fetched = api_instance.download_derivative_sample( created.derivative_sample_id) assert created == fetched, "create response != download response" fetched.derivative_sample_id = None assert samp == fetched, "upload != download response" api_instance.delete_derivative_sample( parent_created.derivative_sample_id) api_instance.delete_derivative_sample(created.derivative_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def test_ds_update(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: samp = openapi_client.DerivativeSample(None) samp.attrs = [ openapi_client.Attr(attr_type='oxford', attr_value='1234567') ] created = api_instance.create_derivative_sample(samp) looked_up = api_instance.download_derivative_samples_by_attr( 'oxford', '1234567') looked_up = looked_up.derivative_samples[0] new_samp = openapi_client.DerivativeSample(None) updated = api_instance.update_derivative_sample( looked_up.derivative_sample_id, new_samp) fetched = api_instance.download_derivative_sample( looked_up.derivative_sample_id) assert updated == fetched, "update response != download response" fetched.derivative_sample_id = None assert new_samp == fetched, "update != download response" api_instance.delete_derivative_sample( looked_up.derivative_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def test_ds_attr_merge(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: ident1 = openapi_client.Attr(attr_type='oxford_id', attr_value='1234') ident2 = openapi_client.Attr(attr_type='roma_id', attr_value='12345') ident3 = openapi_client.Attr(attr_type='lims_id', attr_value='123456') samp1 = openapi_client.DerivativeSample(None) samp1.attrs = [ident1] created1 = api_instance.create_derivative_sample(samp1) samp2 = openapi_client.DerivativeSample(None) samp2.attrs = [ident2] created2 = api_instance.create_derivative_sample(samp2) samp3 = openapi_client.DerivativeSample(None) samp3.attrs = [ident1, ident2, ident3] with pytest.raises(ApiException, status=422): created3 = api_instance.create_derivative_sample(samp3) api_instance.delete_derivative_sample( created1.derivative_sample_id) api_instance.delete_derivative_sample( created2.derivative_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def test_ds_os_attr_lookup(self, api_factory): api_instance = api_factory.OriginalSampleApi() ds_api_instance = api_factory.DerivativeSampleApi() try: samp = openapi_client.OriginalSample(None, study_name='7000-MD-UP') samp.attrs = [ openapi_client.Attr(attr_type='ds_os_attr', attr_value='123456') ] created = api_instance.create_original_sample(samp) samp1 = openapi_client.DerivativeSample(None) samp2 = openapi_client.DerivativeSample(None) samp1.attrs = [ openapi_client.Attr(attr_type='test1', attr_value='test1', attr_source='ds_os_attr') ] samp2.attrs = [ openapi_client.Attr(attr_type='test2', attr_value='test2', attr_source='ds_os_attr') ] samp1.original_sample_id = created.original_sample_id samp2.original_sample_id = created.original_sample_id created1 = ds_api_instance.create_derivative_sample(samp1) created2 = ds_api_instance.create_derivative_sample(samp2) results = ds_api_instance.download_derivative_samples_by_os_attr( 'ds_os_attr', '123456') assert results.count == 2 assert results.derivative_samples[ 0].derivative_sample_id != results.derivative_samples[ 1].derivative_sample_id assert results.derivative_samples[ 0].original_sample_id == results.derivative_samples[ 1].original_sample_id assert results.derivative_samples[ 0].original_sample_id == created.original_sample_id ds_api_instance.delete_derivative_sample( created1.derivative_sample_id) ds_api_instance.delete_derivative_sample( created2.derivative_sample_id) api_instance.delete_original_sample(created.original_sample_id) except ApiException as error: self.check_api_exception( api_factory, "OriginalSampleApi->create_original_sample", error)
def create_derivative_sample_from_values(self, values): d_sample = openapi_client.DerivativeSample(None) idents = [] if 'derivative_sample_id' in values: idents.append( openapi_client.Attr('derivative_sample_id', values['derivative_sample_id'], self._event_set)) if 'derivative_sample_source' in values: idents.append( openapi_client.Attr('derivative_sample_source', values['derivative_sample_source'], self._event_set)) if 'sanger_sample_id' in values: idents.append( openapi_client.Attr('sanger_sample_id', values['sanger_sample_id'], self._event_set)) if 'sample_lims_id' in values and values['sample_lims_id']: idents.append( openapi_client.Attr('sanger_lims_id', values['sample_lims_id'], self._event_set)) if 'dna_prep' in values: d_sample.dna_prep = values['dna_prep'] d_sample.attrs = idents return d_sample
def test_ds_study_lookup_paged(self, api_factory): api_instance = api_factory.OriginalSampleApi() ds_api_instance = api_factory.DerivativeSampleApi() try: study_code = '7003-MD-UP' os_samp = openapi_client.OriginalSample(None, study_name=study_code) os_created = api_instance.create_original_sample(os_samp) for i in range(5): samp = openapi_client.DerivativeSample(None) samp.original_sample_id = os_created.original_sample_id created = ds_api_instance.create_derivative_sample(samp) fetched1 = ds_api_instance.download_derivative_samples_by_study( study_code, start=0, count=2) assert len(fetched1.derivative_samples ) == 2, "Wrong number of original_samples returned" assert fetched1.count == 5, "Wrong total of original_samples returned" ffetched = ds_api_instance.download_derivative_samples( search_filter='studyId:' + study_code, start=0, count=2) assert ffetched == fetched1 fetched2 = ds_api_instance.download_derivative_samples_by_study( study_code, start=2, count=5) #Gets second tranche and also attempts to retrieve more than exist assert len(fetched2.derivative_samples ) == 3, "Wrong number of original_samples returned" assert fetched2.count == 5, "Wrong total of original_samples returned" ids = [] for derivative_sample in fetched1.derivative_samples + fetched2.derivative_samples: assert not derivative_sample.derivative_sample_id in ids, "derivativeSample returned twice" ids.append(derivative_sample.derivative_sample_id) #Check that it's the correct number of *unique* events #Clean up fetch_all = ds_api_instance.download_derivative_samples_by_study( study_code) for derivative_sample in fetch_all.derivative_samples: ds_api_instance.delete_derivative_sample( derivative_sample.derivative_sample_id) api_instance.delete_original_sample(os_created.original_sample_id) except ApiException as error: self.check_api_exception( api_factory, "OriginalSampleApi->create_original_sample", error)
def test_ds_nested_delete_os(self, api_factory): api_instance = api_factory.DerivativeSampleApi() os_api_instance = api_factory.OriginalSampleApi() try: parent_samp = openapi_client.OriginalSample(None) parent_created = os_api_instance.create_original_sample( parent_samp) samp = openapi_client.DerivativeSample(None) samp.original_sample_id = parent_created.original_sample_id created = api_instance.create_derivative_sample(samp) child_samp = openapi_client.DerivativeSample(None) child_samp.parent_derivative_sample_id = created.derivative_sample_id child_created = api_instance.create_derivative_sample(child_samp) api_instance.delete_derivative_sample(created.derivative_sample_id) fetched = api_instance.download_derivative_sample( child_created.derivative_sample_id) assert fetched.original_sample_id == parent_created.original_sample_id api_instance.delete_derivative_sample( child_created.derivative_sample_id) os_api_instance.delete_original_sample( parent_created.original_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def create_test_samples(self, api_factory, study_name): api_instance = api_factory.OriginalSampleApi() ds_api_instance = api_factory.DerivativeSampleApi() study_api = api_factory.StudyApi() samp = openapi_client.OriginalSample(None, study_name=study_name, partner_species='PF') samp.attrs = [ openapi_client.Attr(attr_type='ds_os_attr', attr_value='123456') ] created = api_instance.create_original_sample(samp) study_detail = study_api.download_study(study_name) study_detail.partner_species[0].taxa = [ openapi_client.Taxonomy(taxonomy_id=5833) ] study_api.update_study(study_name, study_detail) samp1 = openapi_client.DerivativeSample(None) samp2 = openapi_client.DerivativeSample(None) samp1.attrs = [ openapi_client.Attr(attr_type='test1', attr_value='test1', attr_source='ds_os_attr') ] samp2.attrs = [ openapi_client.Attr(attr_type='test2', attr_value='test2', attr_source='ds_os_attr') ] samp1.original_sample_id = created.original_sample_id samp2.original_sample_id = created.original_sample_id created1 = ds_api_instance.create_derivative_sample(samp1) created2 = ds_api_instance.create_derivative_sample(samp2) return created, created1, created2
def test_ds_update_duplicate(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: samp = openapi_client.DerivativeSample(None) samp.attrs = [ openapi_client.Attr(attr_type='oxford', attr_value='12345678', attr_source='upd') ] created = api_instance.create_derivative_sample(samp) looked_up = api_instance.download_derivative_samples_by_attr( 'oxford', '12345678') looked_up = looked_up.derivative_samples[0] new_samp = openapi_client.DerivativeSample(None) new_samp.attrs = [ openapi_client.Attr(attr_type='oxford', attr_value='123456789', attr_source='upd') ] new_created = api_instance.create_derivative_sample(new_samp) with pytest.raises(ApiException, status=422): updated = api_instance.update_derivative_sample( looked_up.derivative_sample_id, new_samp) api_instance.delete_derivative_sample( looked_up.derivative_sample_id) api_instance.delete_derivative_sample( new_created.derivative_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def test_ds_delete(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: samp = openapi_client.DerivativeSample(None) created = api_instance.create_derivative_sample(samp) api_instance.delete_derivative_sample(created.derivative_sample_id) with pytest.raises(ApiException, status=404): fetched = api_instance.download_derivative_sample( created.derivative_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def test_ds_attr_lookup_encode(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: test_id = 'MDG/DK_0005' samp = openapi_client.DerivativeSample(None) samp.attrs = [ openapi_client.Attr(attr_type='partner_id', attr_value=test_id, attr_source='encode') ] created = api_instance.create_derivative_sample(samp) fetched = api_instance.download_derivative_sample( created.derivative_sample_id) assert created == fetched, "create response != download response" fetched.derivative_sample_id = None assert samp == fetched, "upload != download response" results = api_instance.download_derivative_samples_by_attr( 'partner_id', urllib.parse.quote_plus(test_id)) looked_up = results.derivative_samples[0] fetched = api_instance.download_derivative_sample( looked_up.derivative_sample_id) assert created == fetched, "create response != download response" fetched.derivative_sample_id = None assert samp == fetched, "upload != download response" api_instance.delete_derivative_sample(created.derivative_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def test_ds_duplicate_key(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: samp = openapi_client.DerivativeSample(None) samp.attrs = [ openapi_client.Attr(attr_type='oxford', attr_value='1234', attr_source='same') ] created = api_instance.create_derivative_sample(samp) with pytest.raises(ApiException, status=422): created = api_instance.create_derivative_sample(samp) api_instance.delete_derivative_sample(created.derivative_sample_id) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->create_derivative_sample", error)
def test_ds_update_missing(self, api_factory): api_instance = api_factory.DerivativeSampleApi() try: new_samp = openapi_client.DerivativeSample(None) fake_id = uuid.uuid4() new_samp.derivative_sample_id = str(fake_id) if api_factory.is_authorized(None): with pytest.raises(ApiException, status=404): updated = api_instance.update_derivative_sample( new_samp.derivative_sample_id, new_samp) else: with pytest.raises(ApiException, status=403): updated = api_instance.update_derivative_sample( new_samp.derivative_sample_id, new_samp) except ApiException as error: self.check_api_exception( api_factory, "DerivativeSampleApi->update_derivative_sample", error)
def test_ad_attr_lookup(self, api_factory): api_instance = api_factory.AssayDataApi() ds_api_instance = api_factory.DerivativeSampleApi() try: samp1 = openapi_client.DerivativeSample(None) created1 = ds_api_instance.create_derivative_sample(samp1) samp = openapi_client.AssayDatum(None) samp.attrs = [ openapi_client.Attr(attr_type='oxford', attr_value='123456') ] samp.derivative_sample_id = created1.derivative_sample_id created = api_instance.create_assay_datum(samp) results = api_instance.download_assay_data_by_attr( 'oxford', '123456') looked_up = results.assay_data[0] fetched = api_instance.download_assay_datum( looked_up.assay_datum_id) assert created == fetched, "create response != download response" fetched.assay_datum_id = None assert samp == fetched, "upload != download response" api_instance.delete_assay_datum(created.assay_datum_id) ds_api_instance.delete_derivative_sample( created1.derivative_sample_id) except ApiException as error: self.check_api_exception(api_factory, "AssayDataApi->create_assay_datum", error)
def test_ad_os_attr_lookup(self, api_factory): api_instance = api_factory.AssayDataApi() os_api_instance = api_factory.OriginalSampleApi() ds_api_instance = api_factory.DerivativeSampleApi() try: samp = openapi_client.OriginalSample(None, study_name='5000-MD-UP') samp.attrs = [ openapi_client.Attr(attr_type='ds_os_attr', attr_value='ad123456') ] created = os_api_instance.create_original_sample(samp) samp1 = openapi_client.DerivativeSample(None) samp2 = openapi_client.DerivativeSample(None) samp1.attrs = [ openapi_client.Attr(attr_type='test1', attr_value='test1', attr_source='ds_os_attr') ] samp2.attrs = [ openapi_client.Attr(attr_type='test2', attr_value='test2', attr_source='ds_os_attr') ] samp1.original_sample_id = created.original_sample_id samp2.original_sample_id = created.original_sample_id created1 = ds_api_instance.create_derivative_sample(samp1) created2 = ds_api_instance.create_derivative_sample(samp2) ad_samp = openapi_client.AssayDatum(None) ad_samp.attrs = [ openapi_client.Attr(attr_type='oxford', attr_value='123456') ] ad_samp.derivative_sample_id = created1.derivative_sample_id ad_created = api_instance.create_assay_datum(ad_samp) results = ds_api_instance.download_derivative_samples_by_os_attr( 'ds_os_attr', 'ad123456') results = api_instance.download_assay_data_by_os_attr( 'ds_os_attr', 'ad123456') looked_up = results.assay_data[0] fetched = api_instance.download_assay_datum( looked_up.assay_datum_id) assert ad_created == fetched, "create response != download response" fetched.assay_datum_id = None assert ad_samp == fetched, "upload != download response" assert looked_up == ad_created api_instance.delete_assay_datum(ad_created.assay_datum_id) ds_api_instance.delete_derivative_sample( created1.derivative_sample_id) ds_api_instance.delete_derivative_sample( created2.derivative_sample_id) os_api_instance.delete_original_sample(created.original_sample_id) except ApiException as error: self.check_api_exception(api_factory, "AssayDataApi->create_assay_datum", error)
def create_test_samples(self, api_factory): created_es = None created_se = None created = None created1 = None created2 = None try: api_instance = api_factory.OriginalSampleApi() loc_api_instance = api_factory.LocationApi() se_api_instance = api_factory.SamplingEventApi() es_api_instance = api_factory.EventSetApi() ds_api_instance = api_factory.DerivativeSampleApi() study_api = api_factory.StudyApi() event_set_name = 'test_hist_event_set_lookup' study_name = '8004-MD-UP' created_es = es_api_instance.create_event_set(event_set_name) loc = openapi_client.Location(None, 28.463, 91.495, 'country', 'Trongsa, Trongsa, Bhutan', 'history_locations.txt', 'BTN') location = loc_api_instance.create_location(loc) sampling_event = openapi_client.SamplingEvent(None, date(2017, 10, 10), doc_accuracy='month') sampling_event.location_id = location.location_id created_se = se_api_instance.create_sampling_event(sampling_event) es_api_instance.create_event_set_item(event_set_name, created_se.sampling_event_id) samp = openapi_client.OriginalSample(None, study_name=study_name, partner_species='PF') samp.attrs = [ openapi_client.Attr(attr_type='ds_os_attr', attr_value='123456') ] created = api_instance.create_original_sample(samp) study_detail = study_api.download_study(study_name) study_detail.partner_species[0].taxa = [ openapi_client.Taxonomy(taxonomy_id=5833) ] study_api.update_study(study_name, study_detail) samp1 = openapi_client.DerivativeSample(None) samp2 = openapi_client.DerivativeSample(None) samp1.attrs = [ openapi_client.Attr(attr_type='test1', attr_value='test1', attr_source='ds_os_attr') ] samp2.attrs = [ openapi_client.Attr(attr_type='test2', attr_value='test2', attr_source='ds_os_attr') ] samp1.original_sample_id = created.original_sample_id samp2.original_sample_id = created.original_sample_id created1 = ds_api_instance.create_derivative_sample(samp1) created2 = ds_api_instance.create_derivative_sample(samp2) created.sampling_event_id = created_se.sampling_event_id api_instance.update_original_sample(created.original_sample_id, created) except ApiException as error: self.check_api_exception( api_factory, "OriginalSampleApi->create_original_sample", error) return created_es, created_se, created, created1, created2