Exemplo n.º 1
0
    def __init__(self,
                 ingest_api,
                 dsp_api,
                 ontology_api=ontology.__api__,
                 exclude_types=None,
                 alias_prefix=None,
                 dsp_validation=True):
        self.logger = logging.getLogger(__name__)
        self.ingest_api = ingest_api
        self.exclude_types = exclude_types if exclude_types else []
        self.alias_prefix = f"{alias_prefix}_" if alias_prefix else ""
        self.ontology_api = ontology_api
        self.dsp_api = dsp_api
        self.dsp_validation = dsp_validation

        self.converter = {
            "project":
            ProjectConverter(ontology_api=ontology_api),
            "sample":
            SampleConverter(ontology_api=ontology_api),
            "study":
            StudyConverter(ontology_api=ontology_api),
            "sequencingRun":
            SequencingRunConverter(ontology_api=ontology_api),
            "sequencingExperiment":
            SequencingExperimentConverter(ontology_api=ontology_api)
        }

        self.converter['sample'].ingest_api = self.ingest_api
Exemplo n.º 2
0
    def test_convert_sample(self):
        # given:
        biomaterial = self.hca_data.get('biomaterial')
        with open(config.JSON_DIR + 'dsp/sample.json',
                  encoding=config.ENCODING) as data_file:
            no_release_date = json.loads(data_file.read())

        # and:
        test_alias = 'hca' + str(randint(0, 1000))
        biomaterial['uuid']['uuid'] = test_alias
        no_release_date['alias'] = test_alias
        no_release_date['attributes']['HCA Biomaterial UUID'] = [{
            'value':
            test_alias
        }]

        # and:
        with_release_date = deepcopy(no_release_date)
        with_release_date['releaseDate'] = '2018-10-11'

        # and:
        converter = SampleConverter(ontology_api=self.ontology_api)
        converter.ingest_api = self.ingest_api

        # when:
        converted_with_release_date = converter.convert({
            'biomaterial': biomaterial,
            'project': {
                'releaseDate': '2018-10-11T14:33:22.111Z'
            }
        })

        # and:
        converted_no_release_date = converter.convert({
            'biomaterial': biomaterial,
            'project': {
                'releaseDate': None
            }
        })

        # then:
        self.assertEqual(with_release_date, converted_with_release_date)
        self.assertEqual(no_release_date, converted_no_release_date)
Exemplo n.º 3
0
    def setUp(self):
        self.dsp_api = DataSubmissionPortal()

        with open(config.JSON_DIR + 'hca/biomaterials.json',
                  encoding=config.ENCODING) as data_file:
            hca_samples = json.loads(data_file.read())

        self.hca_submission = {'samples': hca_samples}
        self.ontology_api = MagicMock()
        self.ontology_api.expand_curie = MagicMock(
            return_value='http://purl.obolibrary.org/obo/UO_0000015')

        self.ingest_api = MagicMock()
        self.ingest_api.url = 'ingest_url'
        self.ingest_api.get_concrete_entity_type = MagicMock(
            return_value='donor_organism')

        self.converter = SampleConverter(ontology_api=self.ontology_api)
        self.converter.ingest_api = self.ingest_api
        pass
Exemplo n.º 4
0
    def test_convert_sample(self):
        biomaterial = self.hca_data.get('biomaterial')

        with open(config.JSON_DIR + 'dsp/sample.json', encoding=config.ENCODING) as data_file:
            expected_json = json.loads(data_file.read())

        test_alias = 'hca' + str(randint(0, 1000))

        biomaterial['uuid']['uuid'] = test_alias
        expected_json['alias'] = test_alias
        expected_json['attributes']['HCA Biomaterial UUID'] = [{'value': test_alias}]

        input = {
            'biomaterial': biomaterial
        }

        converter = SampleConverter(ontology_api=self.ontology_api)
        converter.ingest_api = self.ingest_api
        actual_json = converter.convert(input)

        self.assertEqual(expected_json, actual_json)
Exemplo n.º 5
0
class TestDataSubmissionPortal(unittest.TestCase):
    def setUp(self):
        self.dsp_api = DataSubmissionPortal()

        with open(config.JSON_DIR + 'hca/biomaterials.json',
                  encoding=config.ENCODING) as data_file:
            hca_samples = json.loads(data_file.read())

        self.hca_submission = {'samples': hca_samples}
        self.ontology_api = MagicMock()
        self.ontology_api.expand_curie = MagicMock(
            return_value='http://purl.obolibrary.org/obo/UO_0000015')

        self.ingest_api = MagicMock()
        self.ingest_api.url = 'ingest_url'
        self.ingest_api.get_concrete_entity_type = MagicMock(
            return_value='donor_organism')

        self.converter = SampleConverter(ontology_api=self.ontology_api)
        self.converter.ingest_api = self.ingest_api
        pass

    def tearDown(self):
        self.dsp_api.session.close()

    def test_get_token_given_valid_credentials_return_token(self):
        aap_user = os.environ.get('AAP_API_USER', '')
        aap_password = os.environ.get('AAP_API_PASSWORD', '')

        token_client = AAPTokenClient(username=aap_user, password=aap_password)
        token = token_client.retrieve_token()

        self.assertTrue(token)

    def test_get_token_given_invalid_credentials_return_none(self):
        username = '******'
        password = '******'

        token_client = AAPTokenClient(username=username, password=password)
        token = token_client.retrieve_token()

        self.assertFalse(token)

    def test_create_submission(self):
        submission = self.dsp_api.create_submission()

        delete_url = submission['_links']['self:delete']['href']
        self.dsp_api.delete_submission(delete_url)

        self.assertTrue(submission['_links']['self']['href'])

    def test_get_submission_contents(self):
        submission = self.dsp_api.create_submission()

        get_contents_url = submission['_links']['contents']['href']

        contents = self.dsp_api.get_contents(get_contents_url)

        delete_url = submission['_links']['self:delete']['href']
        self.dsp_api.delete_submission(delete_url)

        self.assertTrue(contents)

    def test_create_sample(self):
        submission = self.dsp_api.create_submission()

        get_contents_url = submission['_links']['contents']['href']
        contents = self.dsp_api.get_contents(get_contents_url)
        create_sample_url = contents['_links']['samples:create']['href']

        samples = self.hca_submission['samples']
        sample = samples[0]
        sample = {'biomaterial': sample}

        converted_sample = self.converter.convert(sample)

        created_sample = self.dsp_api.create_entity(create_sample_url,
                                                    converted_sample)

        # clean up submission in DSP
        delete_url = submission['_links']['self:delete']['href']
        self.dsp_api.delete_submission(delete_url)

        self.assertTrue(created_sample)