1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
import pytest
from pystac_client import CollectionClient
from pystac_client.client import Client
from pystac_client.warnings import FallbackToPystac, MissingLink
from .helpers import STAC_URLS
class TestCollectionClient:
@pytest.mark.vcr
def test_instance(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")
assert isinstance(collection, CollectionClient)
assert str(collection) == "<CollectionClient id=aster-l1t>"
@pytest.mark.vcr
def test_get_items(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")
assert collection is not None
for item in collection.get_items():
assert item.collection_id == collection.id
return
@pytest.mark.vcr
def test_get_items_with_ids(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")
ids = [
"AST_L1T_00312272006020322_20150518201805",
"AST_L1T_00312272006020313_20150518201753",
"AST_L1T_00312272006020304_20150518201753",
]
assert collection is not None
for item in collection.get_items(*ids):
assert item.collection_id == collection.id
assert item.id in ids
@pytest.mark.vcr
def test_get_item(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")
assert collection is not None
item = collection.get_item("AST_L1T_00312272006020322_20150518201805")
assert item
assert item.id == "AST_L1T_00312272006020322_20150518201805"
item = collection.get_item("for-sure-not-a-real-id")
assert item is None
@pytest.mark.vcr
def test_get_item_with_item_search(self) -> None:
client = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection = client.get_collection("aster-l1t")
assert collection is not None
client.set_conforms_to(
[
"https://api.stacspec.org/v1.0.0-rc.2/core",
"https://api.stacspec.org/v1.0.0-rc.2/item-search",
]
)
item = collection.get_item("AST_L1T_00312272006020322_20150518201805")
assert item
assert item.id == "AST_L1T_00312272006020322_20150518201805"
item = collection.get_item("for-sure-not-a-real-id")
assert item is None
with pytest.warns(FallbackToPystac):
item = collection.get_item(
"AST_L1T_00312272006020322_20150518201805", recursive=True
)
assert item
assert item.id == "AST_L1T_00312272006020322_20150518201805"
@pytest.mark.vcr
def test_get_queryables(self) -> None:
api = Client.open(STAC_URLS["PLANETARY-COMPUTER"])
collection_client = api.get_collection("landsat-c2-l2")
assert collection_client is not None
assert isinstance(collection_client, CollectionClient)
with pytest.warns(MissingLink, match="/queryables"):
result = collection_client.get_queryables()
assert "instrument" in result["properties"]
assert "landsat:scene_id" in result["properties"]
|