Exemplo n.º 1
0
    def test_get_registry_url_no_doi(self) -> None:
        # Get the example collection as a dict and remove the sci:doi property
        collection_dict: Dict[str, Any] = Collection.fetch(
            'ref_african_crops_kenya_02_labels').to_dict()
        collection_dict.pop('sci:doi', None)
        collection: Collection = Collection.from_dict(collection_dict)

        assert collection.registry_url is None
Exemplo n.º 2
0
    def test_fetch_item(self) -> None:
        collection = Collection.fetch('ref_african_crops_kenya_02_source')
        item = collection.fetch_item(
            'ref_african_crops_kenya_02_tile_02_20190721')

        assert isinstance(item, pystac.item.Item)
        assert len(item.assets) == 13
Exemplo n.º 3
0
    def test_get_items_error(self, source_collection):
        collection = Collection.fetch('bigearthnet_v1_source')

        with pytest.raises(NotImplementedError) as excinfo:
            collection.get_items()

        assert 'For performance reasons, the get_items method has not been implemented for Collection instances. Please ' \
               'use the Collection.download method to download Collection assets.' == str(excinfo.value)
Exemplo n.º 4
0
    def test_fetch_passes_session_to_instance(self,
                                              requests_mock: "Mocker_Type",
                                              root_url: str) -> None:
        collection_id = 'bigearthnet_v1_source'
        collection_url = urljoin(root_url, f'collections/{collection_id}')

        example_collection = Path(
            __file__).parent / "data" / "bigearthnet_v1_source.json"
        with open(example_collection) as src:
            requests_mock.get(collection_url, json=json.load(src))

        collection = Collection.fetch(collection_id, profile="__anonymous__")
        assert collection.session_kwargs.get("profile") == "__anonymous__"
Exemplo n.º 5
0
    def test_list_anonymously_has_no_key(self, requests_mock: "Mocker_Type",
                                         root_url: str) -> None:
        url = urljoin(root_url, 'collections')

        # Don't really care about the response here, since we're just interested in the request
        # parameters. We test that this gives a valid response in a different test
        requests_mock.get(url, json={"collections": []})

        _ = Collection.list(profile="__anonymous__")

        history = requests_mock.request_history

        actual_url = history[0].url
        qs = parse_qs(urlsplit(actual_url).query)
        assert "key" not in qs
Exemplo n.º 6
0
    def test_fetch_anonymously_has_no_key(self, requests_mock: "Mocker_Type",
                                          root_url: str) -> None:
        collection_id = 'bigearthnet_v1_source'
        url = urljoin(root_url, f'collections/{collection_id}')

        example_collection = Path(
            __file__).parent / "data" / "bigearthnet_v1_source.json"
        with open(example_collection) as src:
            requests_mock.get(url, json=json.load(src))

        _ = Collection.fetch(collection_id, profile="__anonymous__")

        history = requests_mock.request_history

        actual_url = history[0].url
        qs = parse_qs(urlsplit(actual_url).query)
        assert "key" not in qs
Exemplo n.º 7
0
    def test_anonymous_archive_size(self, requests_mock: "Mocker_Type",
                                    root_url: str) -> None:
        collection_id = 'bigearthnet_v1_source'
        example_collection = Path(
            __file__).parent / "data" / "bigearthnet_v1_source.json"
        with open(example_collection) as src:
            collection = Collection.from_dict(json.load(src),
                                              profile="__anonymous__")

        info_url = urljoin(root_url, f'archive/{collection_id}/info')
        requests_mock.get(info_url, json={})

        _ = collection.archive_size

        history = requests_mock.request_history

        actual_url = history[0].url
        qs = parse_qs(urlsplit(actual_url).query)
        assert "key" not in qs
Exemplo n.º 8
0
 def test_list_collections(self, collections):
     collections = Collection.list()
     assert len(collections) == 47
     assert isinstance(collections[0], Collection)
Exemplo n.º 9
0
    def test_download_archive(self, source_collection_archive, source_collection, tmp_path):
        collection = Collection.fetch('bigearthnet_v1_source')
        output_path = collection.download(output_dir=tmp_path)

        assert output_path == tmp_path / 'bigearthnet_v1_source.tar.gz'
        assert output_path.exists()
Exemplo n.º 10
0
    def test_fetch_item(self, source_collection, source_collection_item):
        collection = Collection.fetch('bigearthnet_v1_source')
        item = collection.fetch_item('bigearthnet_v1_source_S2A_MSIL2A_20180526T100031_65_62')

        assert isinstance(item, pystac.Item)
        assert len(item.assets) == 13
Exemplo n.º 11
0
    def test_fetch_collection(self, source_collection):
        collection = Collection.fetch('bigearthnet_v1_source')

        assert isinstance(collection, Collection)
        assert collection.description == 'BigEarthNet v1.0'
Exemplo n.º 12
0
    def test_get_collection_from_file(self, source_collection):
        """The collection can be fetched by passing the MLHub URL to the from_file method."""
        collection = Collection.from_file(source_collection)

        assert isinstance(collection, Collection)
        assert collection.description == 'BigEarthNet v1.0'
Exemplo n.º 13
0
    def test_download_archive(self, tmp_path: "Path_Type") -> None:
        collection = Collection.fetch('ref_african_crops_kenya_02_labels')
        output_path = collection.download(output_dir=tmp_path)

        assert output_path == tmp_path / 'ref_african_crops_kenya_02_labels.tar.gz'
        assert output_path.exists()
Exemplo n.º 14
0
 def test_get_archive_size(self) -> None:
     collection = Collection.fetch('bigearthnet_v1_labels')
     assert collection.archive_size == 173029030
Exemplo n.º 15
0
 def test_get_registry_url(self) -> None:
     collection = Collection.fetch('ref_african_crops_kenya_02_labels')
     assert collection.registry_url == 'https://registry.mlhub.earth/10.34911/rdnt.dw605x'
Exemplo n.º 16
0
 def test_list_collections(self) -> None:
     collections = Collection.list()
     assert isinstance(collections, list)
     assert isinstance(collections[0], Collection)