Skip to content

Commit

Permalink
fix(#711): changed default filter language (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
captaincoordinates authored Jun 21, 2024
1 parent 80064f7 commit 8f400e1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
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

0 comments on commit 8f400e1

Please sign in to comment.