Skip to content

Commit 62bd047

Browse files
committed
fixup the test
1 parent 56ade7f commit 62bd047

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

tests/api/test_api.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
from httpx import AsyncClient
99
from pystac import Collection, Extent, Item, SpatialExtent, TemporalExtent
1010
from stac_fastapi.api.app import StacApi
11+
from stac_fastapi.api.models import create_post_request_model
12+
from stac_fastapi.extensions.core import FieldsExtension, TransactionExtension
1113
from stac_fastapi.types import stac as stac_types
1214

1315
from stac_fastapi.pgstac.core import CoreCrudClient, Settings
1416
from stac_fastapi.pgstac.db import close_db_connection, connect_to_db
17+
from stac_fastapi.pgstac.transactions import TransactionsClient
18+
from stac_fastapi.pgstac.types.search import PgstacSearch
1519

1620
STAC_CORE_ROUTES = [
1721
"GET /",
@@ -632,7 +636,7 @@ async def search(query: Dict[str, Any]) -> List[Item]:
632636

633637

634638
@pytest.mark.asyncio
635-
async def test_wrapped_function() -> None:
639+
async def test_wrapped_function(load_test_data) -> None:
636640
# Ensure wrappers, e.g. Planetary Computer's rate limiting, work.
637641
# https://github.com/gadomski/planetary-computer-apis/blob/2719ccf6ead3e06de0784c39a2918d4d1811368b/pccommon/pccommon/redis.py#L205-L238
638642

@@ -661,15 +665,42 @@ async def _wrapper(*args: Any, **kwargs: Any) -> T:
661665

662666
class Client(CoreCrudClient):
663667
@wrap()
664-
async def all_collections(self, **kwargs) -> stac_types.Collections:
665-
return await super().all_collections(**kwargs)
668+
async def get_collection(
669+
self, collection_id: str, request: Request, **kwargs
670+
) -> stac_types.Item:
671+
return await super().get_collection(
672+
collection_id, request=request, **kwargs
673+
)
666674

667-
api = StacApi(client=Client(), settings=Settings(testing=True))
675+
settings = Settings(testing=True)
676+
extensions = [
677+
TransactionExtension(client=TransactionsClient(), settings=settings),
678+
FieldsExtension(),
679+
]
680+
post_request_model = create_post_request_model(extensions, base_model=PgstacSearch)
681+
api = StacApi(
682+
client=Client(post_request_model=post_request_model),
683+
settings=settings,
684+
extensions=extensions,
685+
search_post_request_model=post_request_model,
686+
)
668687
app = api.app
669688
await connect_to_db(app)
670689
try:
671690
async with AsyncClient(app=app) as client:
672-
response = await client.get("http://test/collections")
673-
assert response.status_code == 200
691+
response = await client.post(
692+
"http://test/collections",
693+
json=load_test_data("test_collection.json"),
694+
)
695+
assert response.status_code == 200
696+
response = await client.post(
697+
"http://test/collections/test-collection/items",
698+
json=load_test_data("test_item.json"),
699+
)
700+
assert response.status_code == 200
701+
response = await client.get(
702+
"http://test/collections/test-collection/items/test-item"
703+
)
704+
assert response.status_code == 200
674705
finally:
675706
await close_db_connection(app)

0 commit comments

Comments
 (0)