Exemplo n.º 1
0
    def test_download_samples_by_study(self, api_factory):

        api_instance = api_factory.SamplingEventApi()
        os_api_instance = api_factory.OriginalSampleApi()
        study_api = api_factory.StudyApi()

        try:

            samp = openapi_client.SamplingEvent(None, doc_accuracy='month')
            created = api_instance.create_sampling_event(samp)
            osamp = openapi_client.OriginalSample(None,
                                                  study_name='2006-MD-UP')
            osamp.sampling_event_id = created.sampling_event_id
            os_created = os_api_instance.create_original_sample(osamp)

            events = api_instance.download_sampling_events_by_study(
                '2006-MD-UP')

            assert events.count == 1, "Event expected"

            os_api_instance.delete_original_sample(
                os_created.original_sample_id)
            api_instance.delete_sampling_event(created.sampling_event_id)

        except ApiException as error:
            self.check_api_exception(
                api_factory, "SamplingEventApi->create_sampling_event", error)
    def test_ds_event_set_lookup(self, api_factory):

        api_instance = api_factory.OriginalSampleApi()
        se_api_instance = api_factory.SamplingEventApi()
        es_api_instance = api_factory.EventSetApi()
        ds_api_instance = api_factory.DerivativeSampleApi()

        try:

            event_set_name = 'test_ds_event_set_lookup'
            study_code = '7004-MD-UP'

            created_es = es_api_instance.create_event_set(event_set_name)

            sampling_event = openapi_client.SamplingEvent(None,
                                                          date(2017, 10, 10),
                                                          doc_accuracy='month')

            created_se = se_api_instance.create_sampling_event(sampling_event)

            created_set = es_api_instance.create_event_set_item(
                event_set_name, created_se.sampling_event_id)

            created, created1, created2 = self.create_test_samples(
                api_factory, study_code)

            created.sampling_event_id = created_se.sampling_event_id

            api_instance.update_original_sample(created.original_sample_id,
                                                created)

            results = ds_api_instance.download_derivative_samples_by_event_set(
                event_set_name)
            looked_up = results.derivative_samples[0]

            fetched = ds_api_instance.download_derivative_sample(
                looked_up.derivative_sample_id)

            assert created1 == fetched or created2 == fetched, "create response != download response"

            assert results.attr_types == ['test1', 'test2']

            se_api_instance.delete_sampling_event(created_se.sampling_event_id)

            es_api_instance.delete_event_set(event_set_name)

            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)

            with pytest.raises(ApiException, status=404):
                results = api_instance.download_original_samples_by_event_set(
                    event_set_name)

        except ApiException as error:
            self.check_api_exception(
                api_factory, "OriginalSampleApi->create_original_sample",
                error)
Exemplo n.º 3
0
    def test_delete_missing_member(self, api_factory):

        api_instance = api_factory.EventSetApi()
        event_api_instance = api_factory.SamplingEventApi()

        try:

            event_set = 'EventSet12'
            created = api_instance.create_event_set(event_set)

            samp = openapi_client.SamplingEvent(None, date(2017, 10, 10))
            created = event_api_instance.create_sampling_event(samp)

            created_set = api_instance.create_event_set_item(
                event_set, created.sampling_event_id)

            api_instance.delete_event_set_item(event_set,
                                               created.sampling_event_id)

            with pytest.raises(ApiException, status=404):
                api_instance.delete_event_set_item(event_set,
                                                   created.sampling_event_id)

            api_instance.delete_event_set(event_set)
            event_api_instance.delete_sampling_event(created.sampling_event_id)

        except ApiException as error:
            self.check_api_exception(api_factory,
                                     "EventSetsApi->create_event_set", error)
Exemplo n.º 4
0
    def create_sampling_event_from_values(self, values):

        doc = None
        doc_accuracy = None
        study_id = None
        ret = None

        idents = []
        if 'sample_individual_id' in values:
            idents.append(
                openapi_client.Attr('individual_id',
                                    values['sample_individual_id'],
                                    self._event_set))
        if 'roma_pk_id' in values:
            idents.append(
                openapi_client.Attr('roma_pk_id', values['roma_pk_id'],
                                    self._event_set))

        if 'doc' in values:
            if isinstance(values['doc'], datetime.date):
                doc = values['doc']
        else:
            if 'year' in values:
                if isinstance(values['year'], datetime.date):
                    doc = values['year']
                    values['doc_accuracy'] = 'year'

        if 'doc_accuracy' in values:
            doc_accuracy = values['doc_accuracy']

        if 'study_id' in values:
            study_id = values['study_id']

        samp = openapi_client.SamplingEvent(None, doc=doc)

        if doc_accuracy:
            samp.doc_accuracy = doc_accuracy

        samp.attrs = idents
        #print(values)
        #print(samp)
        return samp
    def test_ds_event_set_lookup_no_ds(self, api_factory):

        api_instance = api_factory.OriginalSampleApi()
        se_api_instance = api_factory.SamplingEventApi()
        es_api_instance = api_factory.EventSetApi()
        ds_api_instance = api_factory.DerivativeSampleApi()

        try:

            event_set_name = 'test_ds_event_set_lookup'
            study_code = '7005-MD-UP'

            created_es = es_api_instance.create_event_set(event_set_name)

            sampling_event = openapi_client.SamplingEvent(None,
                                                          date(2017, 10, 10),
                                                          doc_accuracy='month')

            created_se = se_api_instance.create_sampling_event(sampling_event)

            created_set = es_api_instance.create_event_set_item(
                event_set_name, created_se.sampling_event_id)

            if api_factory.is_authorized(None):
                res = ds_api_instance.download_derivative_samples_by_event_set(
                    event_set_name)

                assert not res.derivative_samples
            else:
                with pytest.raises(ApiException, status=403):
                    ds_api_instance.download_derivative_samples_by_event_set(
                        event_set_name)

            se_api_instance.delete_sampling_event(created_se.sampling_event_id)

            es_api_instance.delete_event_set(event_set_name)

        except ApiException as error:
            self.check_api_exception(
                api_factory, "OriginalSampleApi->create_original_sample",
                error)
Exemplo n.º 6
0
    def test_create_member(self, api_factory):

        api_instance = api_factory.EventSetApi()
        event_api_instance = api_factory.SamplingEventApi()

        try:

            event_set = 'EventSet2'
            created = api_instance.create_event_set(event_set)

            samp = openapi_client.SamplingEvent(None, date(2017, 10, 10))
            created = event_api_instance.create_sampling_event(samp)

            created_set = api_instance.create_event_set_item(
                event_set, created.sampling_event_id)
            if not api_factory.is_authorized(None):
                pytest.fail(
                    'Unauthorized call to create_event_set_item succeeded')
            fetched_set = api_instance.download_event_set(event_set)

            if not api_factory.is_authorized(None):
                pytest.fail(
                    'Unauthorized call to download_event_set succeeded')

            assert fetched_set.members.sampling_events[
                0].sampling_event_id == created.sampling_event_id
            assert fetched_set.members.count == 1

            api_instance.delete_event_set_item(event_set,
                                               created.sampling_event_id)

            fetched_set = api_instance.download_event_set(event_set)

            assert fetched_set.members.count == 0

            api_instance.delete_event_set(event_set)
            event_api_instance.delete_sampling_event(created.sampling_event_id)

        except ApiException as error:
            self.check_api_exception(api_factory,
                                     "EventSetsApi->create_event_set", error)
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    def test_update_event_set(self, api_factory):

        api_instance = api_factory.EventSetApi()
        event_api_instance = api_factory.SamplingEventApi()

        try:

            event_set = 'EventSet8'
            created = api_instance.create_event_set(event_set)

            samp = openapi_client.SamplingEvent(None, date(2017, 10, 10))
            created = event_api_instance.create_sampling_event(samp)

            samp2 = openapi_client.SamplingEvent(None, date(2017, 10, 11))
            created2 = event_api_instance.create_sampling_event(samp2)

            created_set = api_instance.create_event_set_item(
                event_set, created.sampling_event_id)
            fetched_set1 = api_instance.download_event_set(event_set)

            assert fetched_set1.members.sampling_events[
                0].sampling_event_id == created.sampling_event_id
            assert fetched_set1.members.count == 1
            assert fetched_set1.notes is None

            evsn = openapi_client.EventSetNote('note8', 'note8text')

            fetched_set1.notes = [evsn]
            fetched_set1.members.sampling_events.append(created2)
            fetched_set1.members.count = 2

            api_instance.update_event_set(event_set, fetched_set1)

            fetched_set2 = api_instance.download_event_set(event_set)

            assert fetched_set2.members.count == 2
            assert len(fetched_set2.notes) == 1

            fetched_set2.members = None

            api_instance.update_event_set(event_set, fetched_set2)

            fetched_set3 = api_instance.download_event_set(event_set)

            assert fetched_set3.members.count == 2
            assert len(fetched_set3.notes) == 1

            api_instance.delete_event_set_item(event_set,
                                               created.sampling_event_id)
            api_instance.delete_event_set_item(event_set,
                                               created2.sampling_event_id)

            fetched_set = api_instance.download_event_set(event_set)

            assert fetched_set.members.count == 0

            api_instance.delete_event_set(event_set)
            event_api_instance.delete_sampling_event(created.sampling_event_id)
            event_api_instance.delete_sampling_event(
                created2.sampling_event_id)

        except ApiException as error:
            self.check_api_exception(api_factory,
                                     "EventSetsApi->create_event_set", error)