|
| 1 | +from datetime import datetime |
| 2 | +from typing import List, Optional, Union |
| 3 | + |
| 4 | +import pytest |
| 5 | +from stac_pydantic import Collection, Item |
| 6 | +from stac_pydantic.api.utils import link_factory |
| 7 | + |
| 8 | +from stac_fastapi.types import core, stac |
| 9 | +from stac_fastapi.types.core import NumType |
| 10 | +from stac_fastapi.types.search import BaseSearchPostRequest |
| 11 | + |
| 12 | +collection_links = link_factory.CollectionLinks("/", "test").create_links() |
| 13 | +item_links = link_factory.ItemLinks("/", "test", "test").create_links() |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def _collection(): |
| 18 | + return Collection( |
| 19 | + id="test_collection", |
| 20 | + title="Test Collection", |
| 21 | + description="A test collection", |
| 22 | + keywords=["test"], |
| 23 | + license="proprietary", |
| 24 | + extent={ |
| 25 | + "spatial": {"bbox": [[-180, -90, 180, 90]]}, |
| 26 | + "temporal": {"interval": [["2000-01-01T00:00:00Z", None]]}, |
| 27 | + }, |
| 28 | + links=collection_links, |
| 29 | + ) |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture |
| 33 | +def collection(_collection: Collection): |
| 34 | + return _collection.json() |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture |
| 38 | +def collection_dict(_collection: Collection): |
| 39 | + return _collection.dict() |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def _item(): |
| 44 | + return Item( |
| 45 | + id="test_item", |
| 46 | + type="Feature", |
| 47 | + geometry={"type": "Point", "coordinates": [0, 0]}, |
| 48 | + bbox=[-180, -90, 180, 90], |
| 49 | + properties={"datetime": "2000-01-01T00:00:00Z"}, |
| 50 | + links=item_links, |
| 51 | + assets={}, |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.fixture |
| 56 | +def item(_item: Item): |
| 57 | + return _item.json() |
| 58 | + |
| 59 | + |
| 60 | +@pytest.fixture |
| 61 | +def item_dict(_item: Item): |
| 62 | + return _item.dict() |
| 63 | + |
| 64 | + |
| 65 | +@pytest.fixture |
| 66 | +def TestCoreClient(collection_dict, item_dict): |
| 67 | + class CoreClient(core.BaseCoreClient): |
| 68 | + def post_search( |
| 69 | + self, search_request: BaseSearchPostRequest, **kwargs |
| 70 | + ) -> stac.ItemCollection: |
| 71 | + return stac.ItemCollection( |
| 72 | + type="FeatureCollection", features=[stac.Item(**item_dict)] |
| 73 | + ) |
| 74 | + |
| 75 | + def get_search( |
| 76 | + self, |
| 77 | + collections: Optional[List[str]] = None, |
| 78 | + ids: Optional[List[str]] = None, |
| 79 | + bbox: Optional[List[NumType]] = None, |
| 80 | + intersects: Optional[str] = None, |
| 81 | + datetime: Optional[Union[str, datetime]] = None, |
| 82 | + limit: Optional[int] = 10, |
| 83 | + **kwargs, |
| 84 | + ) -> stac.ItemCollection: |
| 85 | + return stac.ItemCollection( |
| 86 | + type="FeatureCollection", features=[stac.Item(**item_dict)] |
| 87 | + ) |
| 88 | + |
| 89 | + def get_item(self, item_id: str, collection_id: str, **kwargs) -> stac.Item: |
| 90 | + return stac.Item(**item_dict) |
| 91 | + |
| 92 | + def all_collections(self, **kwargs) -> stac.Collections: |
| 93 | + return stac.Collections( |
| 94 | + collections=[stac.Collection(**collection_dict)], |
| 95 | + links=[ |
| 96 | + {"href": "test", "rel": "root"}, |
| 97 | + {"href": "test", "rel": "self"}, |
| 98 | + {"href": "test", "rel": "parent"}, |
| 99 | + ], |
| 100 | + ) |
| 101 | + |
| 102 | + def get_collection(self, collection_id: str, **kwargs) -> stac.Collection: |
| 103 | + return stac.Collection(**collection_dict) |
| 104 | + |
| 105 | + def item_collection( |
| 106 | + self, |
| 107 | + collection_id: str, |
| 108 | + bbox: Optional[List[Union[float, int]]] = None, |
| 109 | + datetime: Optional[Union[str, datetime]] = None, |
| 110 | + limit: int = 10, |
| 111 | + token: str = None, |
| 112 | + **kwargs, |
| 113 | + ) -> stac.ItemCollection: |
| 114 | + return stac.ItemCollection( |
| 115 | + type="FeatureCollection", features=[stac.Item(**item_dict)] |
| 116 | + ) |
| 117 | + |
| 118 | + return CoreClient |
0 commit comments