Exemplo n.º 1
0
def test_catalogue_of_life(tmpdir):
    data = fixtures('data_providers', 'catalogueoflife')
    id_ = '9249d9473aac5c8e99fb9d758ced91ec'
    repos = create_repos(tmpdir)

    with patch('pytsammalex.util.requests',
               MockRequests(content=data['identify'])):
        prov = CatalogueOfLife(Path(repos))
        assert (prov.identify('x') == id_)

    with patch('pytsammalex.util.requests',
               MockRequests(content=data['metadata'])):
        prov = CatalogueOfLife(Path(repos))
        md = prov.cached_metadata('test', id_)
        taxon = {}
        prov.update(taxon, md)
        assert (
                taxon ==
                {
                    'catalogueoflife_url': 'http://www.catalogueoflife.org/col/'
                                           'browse/tree/id/'
                                           '9249d9473aac5c8e99fb9d758ced91ec',
                    'class': 'Mammalia',
                    'family': 'Felidae',
                    'kingdom': 'Animalia',
                    'order': 'Carnivora',
                    'phylum': 'Chordata'})
Exemplo n.º 2
0
def _provider_img_data(cls):
    prov = cls(None)
    return (prov,
            Staged_images.fromdict({
                'id': prov.__example__[0],
                'taxa__id': 'abc'
            }), fixtures('image_providers', prov.__class__.__name__.lower()))
Exemplo n.º 3
0
def test_catalogue_of_life(tmpdir):
    data = fixtures('data_providers', 'catalogueoflife')
    id_ = '9249d9473aac5c8e99fb9d758ced91ec'
    repos = create_repos(tmpdir)

    with patch('pytsammalex.util.requests',
               MockRequests(content=data['identify'])):
        prov = CatalogueOfLife(Path(repos))
        assert (prov.identify('x') == id_)

    with patch('pytsammalex.util.requests',
               MockRequests(content=data['metadata'])):
        prov = CatalogueOfLife(Path(repos))
        md = prov.cached_metadata('test', id_)
        taxon = {}
        prov.update(taxon, md)
        assert (taxon == {
            'catalogueoflife_url':
            'http://www.catalogueoflife.org/col/'
            'browse/tree/id/'
            '9249d9473aac5c8e99fb9d758ced91ec',
            'class':
            'Mammalia',
            'family':
            'Felidae',
            'kingdom':
            'Animalia',
            'order':
            'Carnivora',
            'phylum':
            'Chordata'
        })
    def test_Eol(self):
        from pytsammalex.data_providers.eol import EOL

        data = fixtures('data_providers', 'eol')
        with patch(
                'pytsammalex.util.requests',
                MockRequests(json=[
                    data['identify'], data['metadata'], data['hierarchy']
                ])):
            prov = EOL(create_repos(self.tmp_path()))
            taxon = {'id': 'pantheraleo', 'name': 'Panthera leo'}
            prov.update_taxon(taxon)
            self.assertEqual(
                taxon, {
                    'eol_id': 328672,
                    'english_name': 'Asian lion',
                    'id': 'pantheraleo',
                    'name': 'Panthera leo',
                    'class': 'Mammalia',
                    'family': 'Felidae',
                    'genus': 'Panthera',
                    'kingdom': 'Animalia',
                    'order': 'Carnivora',
                    'phylum': 'Chordata',
                    'taxonRank': 'species'
                })
    def test_Catalogueoflife(self):
        from pytsammalex.data_providers.catalogueoflife import CatalogueOfLife

        data = fixtures('data_providers', 'catalogueoflife')
        id_ = '9249d9473aac5c8e99fb9d758ced91ec'
        repos = create_repos(self.tmp_path())
        with patch('pytsammalex.util.requests',
                   MockRequests(content=data['identify'])):
            prov = CatalogueOfLife(repos)
            self.assertEqual(prov.identify('x'), id_)

        with patch('pytsammalex.util.requests',
                   MockRequests(content=data['metadata'])):
            prov = CatalogueOfLife(repos)
            md = prov.cached_metadata('test', id_)
            taxon = {}
            prov.update(taxon, md)
            self.assertEqual(
                taxon, {
                    'catalogueoflife_url':
                    'http://www.catalogueoflife.org/col/browse/tree/id/9249d9473aac5c8e99fb9d758ced91ec',
                    'class': 'Mammalia',
                    'family': 'Felidae',
                    'kingdom': 'Animalia',
                    'order': 'Carnivora',
                    'phylum': 'Chordata'
                })
Exemplo n.º 6
0
def test_gbif(tmpdir):
    data = fixtures('data_providers', 'gbif')
    with patch('pytsammalex.util.requests',
               MockRequests(json=[data['identify'], data['metadata']])):
        prov = GBIF(Path(create_repos(tmpdir)))
        taxon = {'id': 'pantheraleo', 'name': 'Panthera leo'}
        prov.update_taxon(taxon)
        assert (taxon == {
            'gbif_id': 5219404,
            'id': 'pantheraleo',
            'name': 'Panthera leo',
            'class': 'Mammalia',
            'family': 'Felidae',
            'genus': 'Panthera',
            'kingdom': 'Animalia',
            'order': 'Carnivora',
            'phylum': 'Chordata',
            'taxonRank': 'species'
        })
Exemplo n.º 7
0
def test_gbif(tmpdir):
    data = fixtures('data_providers', 'gbif')
    with patch(
            'pytsammalex.util.requests',
            MockRequests(json=[data['identify'], data['metadata']])):
        prov = GBIF(Path(create_repos(tmpdir)))
        taxon = {'id': 'pantheraleo', 'name': 'Panthera leo'}
        prov.update_taxon(taxon)
        assert (
                taxon ==
                {
                    'gbif_id': 5219404,
                    'id': 'pantheraleo',
                    'name': 'Panthera leo',
                    'class': 'Mammalia',
                    'family': 'Felidae',
                    'genus': 'Panthera',
                    'kingdom': 'Animalia',
                    'order': 'Carnivora',
                    'phylum': 'Chordata',
                    'taxonRank': 'species'})
    def test_Gbif(self):
        from pytsammalex.data_providers.gbif import GBIF

        data = fixtures('data_providers', 'gbif')
        with patch('pytsammalex.util.requests',
                   MockRequests(json=[data['identify'], data['metadata']])):
            prov = GBIF(create_repos(self.tmp_path()))
            taxon = {'id': 'pantheraleo', 'name': 'Panthera leo'}
            prov.update_taxon(taxon)
            self.assertEqual(
                taxon, {
                    'gbif_id': 5219404,
                    'id': 'pantheraleo',
                    'name': 'Panthera leo',
                    'class': 'Mammalia',
                    'family': 'Felidae',
                    'genus': 'Panthera',
                    'kingdom': 'Animalia',
                    'order': 'Carnivora',
                    'phylum': 'Chordata',
                    'taxonRank': 'species'
                })
Exemplo n.º 9
0
def test_eol(tmpdir):
    data = fixtures('data_providers', 'eol')
    with patch(
            'pytsammalex.util.requests',
            MockRequests(
                json=[data['identify'], data['metadata'], data['hierarchy']])
    ):
        prov = EOL(Path(create_repos(tmpdir)))
        taxon = {'id': 'pantheraleo', 'name': 'Panthera leo'}
        prov.update_taxon(taxon)
        assert (
                taxon ==
                {
                    'eol_id': 328672,
                    'english_name': 'Asian lion',
                    'id': 'pantheraleo',
                    'name': 'Panthera leo',
                    'class': 'Mammalia',
                    'family': 'Felidae',
                    'genus': 'Panthera',
                    'kingdom': 'Animalia',
                    'order': 'Carnivora',
                    'phylum': 'Chordata',
                    'taxonRank': 'species'})
Exemplo n.º 10
0
def _provider_img_data(cls):
    prov = cls(None)
    return (
        prov,
        Staged_images.fromdict({'id': prov.__example__[0], 'taxa__id': 'abc'}),
        fixtures('image_providers', prov.__class__.__name__.lower()))