Skip to content

Commit

Permalink
add tests and remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Aug 1, 2024
1 parent 52cd1ab commit f7f39db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.
52 changes: 7 additions & 45 deletions stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
from stac_fastapi.types.errors import InvalidQueryParameter, NotFoundError
from stac_fastapi.types.requests import get_base_url
from stac_fastapi.types.rfc3339 import DateTimeType
from stac_fastapi.types.stac import (
Collection,
Collections,
Item,
ItemCollection,
LandingPage,
)
from stac_fastapi.types.stac import Collection, Collections, Item, ItemCollection
from stac_pydantic.links import Relations
from stac_pydantic.shared import BBox, MimeTypes

Expand All @@ -45,30 +39,6 @@
class CoreCrudClient(AsyncBaseCoreClient):
"""Client for core endpoints defined by stac."""

async def landing_page(self, **kwargs) -> LandingPage:
"""Landing page.
Called with `GET /`.
Returns:
API landing page, serving as an entry point to the API.
"""
request: Request = kwargs["request"]
base_url = get_base_url(request)
landing_page = await super().landing_page(**kwargs)

if self.extension_is_enabled("FilterExtension"):
landing_page["links"].append(
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
"type": "application/schema+json",
"title": "Queryables",
"href": urljoin(base_url, "queryables"),
}
)

return landing_page

async def all_collections(self, request: Request, **kwargs) -> Collections:
"""Read all collections from the database."""
base_url = get_base_url(request)
Expand All @@ -90,8 +60,8 @@ async def all_collections(self, request: Request, **kwargs) -> Collections:
if self.extension_is_enabled("FilterExtension"):
coll["links"].append(
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
"type": "application/schema+json",
"rel": Relations.queryables.value,
"type": MimeTypes.jsonschema.value,
"title": "Queryables",
"href": urljoin(
base_url, f"collections/{coll['id']}/queryables"
Expand Down Expand Up @@ -155,8 +125,8 @@ async def get_collection(
base_url = get_base_url(request)
collection["links"].append(
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables",
"type": "application/schema+json",
"rel": Relations.queryables.value,
"type": MimeTypes.jsonschema.value,
"title": "Queryables",
"href": urljoin(base_url, f"collections/{collection_id}/queryables"),
}
Expand Down Expand Up @@ -339,8 +309,8 @@ async def item_collection(
}

if self.extension_is_enabled("FilterExtension"):
filter_lang = request.query_params.get("filter-lang", None)
filter = request.query_params.get("filter", "").strip()
filter_lang = kwargs.get("filter_lang", None)
filter = kwargs.get("filter", "").strip()

if len(filter) > 0 and filter_lang == "cql2-text":
ast = parse_cql2_text(filter)
Expand Down Expand Up @@ -439,14 +409,6 @@ async def get_search( # noqa: C901
Returns:
ItemCollection containing items which match the search criteria.
"""
query_params = str(request.query_params)

# Kludgy fix because using factory does not allow alias for filter-lang
if filter_lang is None:
match = re.search(r"filter-lang=([a-z0-9-]+)", query_params, re.IGNORECASE)
if match:
filter_lang = match.group(1)

# Parse request parameters
base_args = {
"collections": collections,
Expand Down
10 changes: 10 additions & 0 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ async def test_get_search_content_type(app_client):
assert resp.headers["content-type"] == "application/geo+json"


async def test_landing_links(app_client):
"""test landing page links."""
landing = await app_client.get("/")
assert landing.status_code == 200, landing.text
assert "Queryables" in [link.get("title") for link in landing.json()["links"]]


async def test_get_queryables_content_type(app_client, load_test_collection):
resp = await app_client.get("queryables")
assert resp.headers["content-type"] == "application/schema+json"
Expand Down Expand Up @@ -743,6 +750,9 @@ async def test_no_extension(
async with AsyncClient(transport=ASGITransport(app=app)) as client:
landing = await client.get("http://test/")
assert landing.status_code == 200, landing.text
assert "Queryables" not in [
link.get("title") for link in landing.json()["links"]
]

collection = await client.get("http://test/collections/test-collection")
assert collection.status_code == 200, collection.text
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ def api_client(request, database):
items_get_request_model = create_request_model(
model_name="ItemCollectionUri",
base_model=ItemCollectionUri,
mixins=[TokenPaginationExtension().GET],
mixins=[
TokenPaginationExtension().GET,
FilterExtension(client=FiltersClient()).GET,
],
request_type="GET",
)
search_get_request_model = create_get_request_model(extensions)
Expand Down
8 changes: 8 additions & 0 deletions tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,14 @@ async def test_get_filter_cql2text(app_client, load_test_data, load_test_collect
resp_json = resp.json()
assert len(resp.json()["features"]) == 0

filter = f"proj:epsg={epsg}"
params = {"filter": filter, "filter-lang": "cql2-text"}
resp = await app_client.get(
f"/collections/{test_item['collection']}/items", params=params
)
resp_json = resp.json()
assert len(resp.json()["features"]) == 1


async def test_item_merge_raster_bands(
app_client, load_test2_item, load_test2_collection
Expand Down

0 comments on commit f7f39db

Please sign in to comment.