Skip to content
Draft
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
33 changes: 33 additions & 0 deletions tests/resources/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Callable, Optional

import pystac
Expand Down Expand Up @@ -642,3 +643,35 @@ async def test_get_collections_search_offset_1(
prev_link = list(filter(lambda link: link["rel"] == "previous", links))[0]
# offset=0 should not be in the previous link (because it's useless)
assert "offset" not in prev_link["href"]


@pytest.mark.parametrize(
"filter, filter_lang, expected_count",
[
("true", "cql2-text", 1),
("1=1", "cql2-text", 1),
("true", "cql2-json", 1),
(json.dumps({"op": "=", "args": [1.0, 1.0]}), "cql2-json", 1),
("false", "cql2-text", 0),
("1=0", "cql2-text", 0),
("false", "cql2-json", 0),
(json.dumps({"op": "=", "args": [1.0, 1.0]}), "cql2-json", 0),
],
)
async def test_get_collections_filter(
app_client,
load_test_collection,
load_test2_collection,
filter,
filter_lang,
expected_count,
):
"""
Test CQL2 filters on the collections endpoint
"""
resp = await app_client.get(
"/collections",
params={"filter": filter, "filter-lang": filter_lang},
)
assert resp.status_code == 200
assert len(resp.json()["collections"]) == expected_count
45 changes: 21 additions & 24 deletions tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,40 +1503,37 @@ async def test_search_datetime_validation_errors(app_client):
assert resp.status_code == 400


async def test_get_filter_cql2text(app_client, load_test_data, load_test_collection):
@pytest.mark.parametrize(
"cql2_filter,expected_count",
[
("true", 1),
("proj:epsg=32756", 1),
("proj:epsg=32756 AND collection = 'test-collection'", 1),
("false", 1), # Bad boolean
("proj:epsg=11111", 0), # Bad epsg
("proj:epsg=32756 AND collection = 'bad-collection'", 0), # Bad collection
],
)
async def test_get_filter_cql2text(
app_client, load_test_data, load_test_collection, cql2_filter, expected_count
):
"""Test GET search with cql2-text"""
test_item = load_test_data("test_item.json")
resp = await app_client.post(
f"/collections/{test_item['collection']}/items", json=test_item
)
assert resp.status_code == 201

epsg = test_item["properties"]["proj:epsg"]
collection = test_item["collection"]

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

filter = f"proj:epsg={epsg + 1} AND collection = '{collection}'"
params = {"filter": filter, "filter-lang": "cql2-text"}
resp = await app_client.get("/search", params=params)
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
"/search", params={"filter": cql2_filter, "filter-lang": "cql2-text"}
)
resp_json = resp.json()
assert len(resp.json()["features"]) == 1
assert len(resp.json()["features"]) == expected_count
if expected_count == 1:
assert (
resp_json["features"][0]["properties"]["proj:epsg"]
== test_item["properties"]["proj:epsg"]
)


async def test_item_merge_raster_bands(
Expand Down
Loading