Skip to content

Commit

Permalink
sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Jul 18, 2024
1 parent 6de61ff commit b5c8ff3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""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
from .pagination import PaginationExtension, TokenPaginationExtension
from .query import QueryExtension
from .sort import SortExtension
from .transaction import TransactionExtension
from .collection_search import CollectionSearchExtension

__all__ = (
"AggregationExtension",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,4 +35,3 @@ class FreeTextGetRequest(APIRequest):
Optional[str],
Query(description="A basic free-text search parameter."),
] = attr.ib(default=None)

77 changes: 56 additions & 21 deletions stac_fastapi/extensions/tests/test_collection_search.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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"]


Expand Down Expand Up @@ -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()
Expand All @@ -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"]

0 comments on commit b5c8ff3

Please sign in to comment.