Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#711 changed default filter language #712

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased] - TBD

### Fixed

* Updated default filter language in filter extension's POST search request model to match the extension's documentation [#711](https://github.com/stac-utils/stac-fastapi/issues/711)

## [3.0.0a3] - 2024-06-13

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class FilterExtensionPostRequest(BaseModel):

filter: Optional[Dict[str, Any]] = None
filter_crs: Optional[str] = Field(alias="filter-crs", default=None)
filter_lang: Optional[FilterLang] = Field(alias="filter-lang", default="cql-json")
filter_lang: Optional[FilterLang] = Field(alias="filter-lang", default="cql2-json")
75 changes: 75 additions & 0 deletions stac_fastapi/extensions/tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from typing import Iterator

import pytest
from starlette.testclient import TestClient

from stac_fastapi.api.app import StacApi
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
from stac_fastapi.extensions.core import FilterExtension
from stac_fastapi.types.config import ApiSettings
from stac_fastapi.types.core import BaseCoreClient


class DummyCoreClient(BaseCoreClient):
def all_collections(self, *args, **kwargs):
raise NotImplementedError

def get_collection(self, *args, **kwargs):
raise NotImplementedError

def get_item(self, *args, **kwargs):
raise NotImplementedError

def get_search(self, *args, **kwargs):
raise NotImplementedError

def post_search(self, *args, **kwargs):
return args[0].model_dump()

def item_collection(self, *args, **kwargs):
raise NotImplementedError


@pytest.fixture
def client() -> Iterator[TestClient]:
settings = ApiSettings()
extensions = [FilterExtension()]
api = StacApi(
settings=settings,
client=DummyCoreClient(),
extensions=extensions,
search_get_request_model=create_get_request_model(extensions),
search_post_request_model=create_post_request_model(extensions),
)
with TestClient(api.app) as client:
yield client


def test_search_filter_post_filter_lang_default(client: TestClient):
"""Test search POST endpoint with filter ext."""
response = client.post(
"/search",
json={
"collections": ["test"],
"filter": {"op": "=", "args": [{"property": "test_property"}, "test-value"]},
},
)
assert response.is_success, response.json()
response_dict = response.json()
assert response_dict["filter_lang"] == "cql2-json"


def test_search_filter_post_filter_lang_non_default(client: TestClient):
"""Test search POST endpoint with filter ext."""
filter_lang_value = "cql2-text"
response = client.post(
"/search",
json={
"collections": ["test"],
"filter": {"op": "=", "args": [{"property": "test_property"}, "test-value"]},
"filter-lang": filter_lang_value,
},
)
assert response.is_success, response.json()
response_dict = response.json()
assert response_dict["filter_lang"] == filter_lang_value