From b5c8ff3ed77767bc7994f6be945f5bd9c4841274 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 18 Jul 2024 10:31:16 +0200 Subject: [PATCH] sketch --- .../stac_fastapi/extensions/core/__init__.py | 2 +- .../core/collection_search/request.py | 5 +- .../tests/test_collection_search.py | 77 ++++++++++++++----- 3 files changed, 59 insertions(+), 25 deletions(-) diff --git a/stac_fastapi/extensions/stac_fastapi/extensions/core/__init__.py b/stac_fastapi/extensions/stac_fastapi/extensions/core/__init__.py index e39ad8c0..0cb89183 100644 --- a/stac_fastapi/extensions/stac_fastapi/extensions/core/__init__.py +++ b/stac_fastapi/extensions/stac_fastapi/extensions/core/__init__.py @@ -1,6 +1,7 @@ """stac_api.extensions.core module.""" from .aggregation import AggregationExtension +from .collection_search import CollectionSearchExtension from .context import ContextExtension from .fields import FieldsExtension from .filter import FilterExtension @@ -8,7 +9,6 @@ from .query import QueryExtension from .sort import SortExtension from .transaction import TransactionExtension -from .collection_search import CollectionSearchExtension __all__ = ( "AggregationExtension", diff --git a/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/request.py b/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/request.py index 6845bdaa..8be16763 100644 --- a/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/request.py +++ b/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/request.py @@ -4,11 +4,11 @@ import attr from fastapi import Query +from stac_pydantic.shared import BBox from typing_extensions import Annotated -from stac_pydantic.shared import BBox from stac_fastapi.types.rfc3339 import DateTimeType -from stac_fastapi.types.search import APIRequest, _datetime_converter, _bbox_converter +from stac_fastapi.types.search import APIRequest, _bbox_converter, _datetime_converter @attr.s @@ -35,4 +35,3 @@ class FreeTextGetRequest(APIRequest): Optional[str], Query(description="A basic free-text search parameter."), ] = attr.ib(default=None) - diff --git a/stac_fastapi/extensions/tests/test_collection_search.py b/stac_fastapi/extensions/tests/test_collection_search.py index a82a10de..ccd76345 100644 --- a/stac_fastapi/extensions/tests/test_collection_search.py +++ b/stac_fastapi/extensions/tests/test_collection_search.py @@ -1,16 +1,18 @@ import json -from urllib.parse import quote_plus, unquote_plus +from urllib.parse import quote_plus -import pytest -from fastapi import Depends, FastAPI from starlette.testclient import TestClient from stac_fastapi.api.app import StacApi - from stac_fastapi.api.models import create_request_model from stac_fastapi.extensions.core import CollectionSearchExtension -from stac_fastapi.extensions.core.collection_search.collection_search import ConformanceClasses -from stac_fastapi.extensions.core.collection_search.request import CollectionSearchExtensionGetRequest, FreeTextGetRequest +from stac_fastapi.extensions.core.collection_search.collection_search import ( + ConformanceClasses, +) +from stac_fastapi.extensions.core.collection_search.request import ( + CollectionSearchExtensionGetRequest, + FreeTextGetRequest, +) from stac_fastapi.extensions.core.fields.request import FieldsExtensionGetRequest from stac_fastapi.extensions.core.filter.request import FilterExtensionGetRequest from stac_fastapi.extensions.core.query.request import QueryExtensionGetRequest @@ -52,8 +54,14 @@ def test_collection_search_extension_default(): response = client.get("/conformance") assert response.is_success, response.json() response_dict = response.json() - assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search" in response_dict["conformsTo"] - assert "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query" in response_dict["conformsTo"] + assert ( + "https://api.stacspec.org/v1.0.0-rc.1/collection-search" + in response_dict["conformsTo"] + ) + assert ( + "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query" + in response_dict["conformsTo"] + ) response = client.get("/collections") assert response.is_success, response.json() @@ -68,12 +76,15 @@ def test_collection_search_extension_default(): "datetime": "2020-06-13T13:00:00Z/2020-06-13T14:00:00Z", "bbox": "-175.05,-85.05,175.05,85.05", "limit": 100, - } + }, ) assert response.is_success, response.json() response_dict = response.json() assert [-175.05, -85.05, 175.05, 85.05] == response_dict["bbox"] - assert ['2020-06-13T13:00:00+00:00', '2020-06-13T14:00:00+00:00'] == response_dict["datetime"] + assert [ + "2020-06-13T13:00:00+00:00", + "2020-06-13T14:00:00+00:00", + ] == response_dict["datetime"] assert 100 == response_dict["limit"] @@ -114,13 +125,34 @@ def test_collection_search_extension_models(): response = client.get("/conformance") assert response.is_success, response.json() response_dict = response.json() - assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search" in response_dict["conformsTo"] - assert "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query" in response_dict["conformsTo"] - assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search#free-text" in response_dict["conformsTo"] - assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search#filter" in response_dict["conformsTo"] - assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search#query" in response_dict["conformsTo"] - assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search#sort" in response_dict["conformsTo"] - assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search#fields" in response_dict["conformsTo"] + assert ( + "https://api.stacspec.org/v1.0.0-rc.1/collection-search" + in response_dict["conformsTo"] + ) + assert ( + "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query" + in response_dict["conformsTo"] + ) + assert ( + "https://api.stacspec.org/v1.0.0-rc.1/collection-search#free-text" + in response_dict["conformsTo"] + ) + assert ( + "https://api.stacspec.org/v1.0.0-rc.1/collection-search#filter" + in response_dict["conformsTo"] + ) + assert ( + "https://api.stacspec.org/v1.0.0-rc.1/collection-search#query" + in response_dict["conformsTo"] + ) + assert ( + "https://api.stacspec.org/v1.0.0-rc.1/collection-search#sort" + in response_dict["conformsTo"] + ) + assert ( + "https://api.stacspec.org/v1.0.0-rc.1/collection-search#fields" + in response_dict["conformsTo"] + ) response = client.get("/collections") assert response.is_success, response.json() @@ -147,17 +179,20 @@ def test_collection_search_extension_models(): ), "sortby": "-gsd,-datetime", "fields": "properties.datetime", - } + }, ) assert response.is_success, response.json() response_dict = response.json() assert [-175.05, -85.05, 175.05, 85.05] == response_dict["bbox"] - assert ['2020-06-13T13:00:00+00:00', '2020-06-13T14:00:00+00:00'] == response_dict["datetime"] + assert [ + "2020-06-13T13:00:00+00:00", + "2020-06-13T14:00:00+00:00", + ] == response_dict["datetime"] assert 100 == response_dict["limit"] assert "EO,Earth Observation" == response_dict["q"] assert "id='item_id' AND collection='collection_id'" == response_dict["filter"] assert "filter_crs" in response_dict assert "cql2-text" in response_dict["filter_lang"] assert "query" in response_dict - assert ['-gsd', '-datetime'] == response_dict["sortby"] - assert ['properties.datetime'] == response_dict["fields"] + assert ["-gsd", "-datetime"] == response_dict["sortby"] + assert ["properties.datetime"] == response_dict["fields"]