|
8 | 8 | from httpx import AsyncClient
|
9 | 9 | from pystac import Collection, Extent, Item, SpatialExtent, TemporalExtent
|
10 | 10 | 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 |
11 | 13 | from stac_fastapi.types import stac as stac_types
|
12 | 14 |
|
13 | 15 | from stac_fastapi.pgstac.core import CoreCrudClient, Settings
|
14 | 16 | 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 |
15 | 19 |
|
16 | 20 | STAC_CORE_ROUTES = [
|
17 | 21 | "GET /",
|
@@ -632,7 +636,7 @@ async def search(query: Dict[str, Any]) -> List[Item]:
|
632 | 636 |
|
633 | 637 |
|
634 | 638 | @pytest.mark.asyncio
|
635 |
| -async def test_wrapped_function() -> None: |
| 639 | +async def test_wrapped_function(load_test_data) -> None: |
636 | 640 | # Ensure wrappers, e.g. Planetary Computer's rate limiting, work.
|
637 | 641 | # https://github.com/gadomski/planetary-computer-apis/blob/2719ccf6ead3e06de0784c39a2918d4d1811368b/pccommon/pccommon/redis.py#L205-L238
|
638 | 642 |
|
@@ -661,15 +665,42 @@ async def _wrapper(*args: Any, **kwargs: Any) -> T:
|
661 | 665 |
|
662 | 666 | class Client(CoreCrudClient):
|
663 | 667 | @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 | + ) |
666 | 674 |
|
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 | + ) |
668 | 687 | app = api.app
|
669 | 688 | await connect_to_db(app)
|
670 | 689 | try:
|
671 | 690 | 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 |
674 | 705 | finally:
|
675 | 706 | await close_db_connection(app)
|
0 commit comments