From 546757845a917a1bc3a2b257a1f42d02f8d7cf3a Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Thu, 9 Oct 2025 10:23:20 -0600 Subject: [PATCH 1/4] Add failing tests --- tests/resources/test_collection.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/resources/test_collection.py b/tests/resources/test_collection.py index 013f9ba..2216a2f 100644 --- a/tests/resources/test_collection.py +++ b/tests/resources/test_collection.py @@ -642,3 +642,24 @@ 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", + [ + "true", + "1=1", + "false", + "1=0", + ], +) +async def test_get_collections_filter( + app_client, load_test_collection, load_test2_collection, filter +): + """ + Test CQL2 filters on the collections endpoint + """ + resp = await app_client.get( + "/collections", + params={"filter": filter}, + ) + assert resp.status_code == 200 From 5c55fb4433d7edb0345102e8a349370f501af7cf Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Thu, 9 Oct 2025 09:29:50 -0700 Subject: [PATCH 2/4] Mv test --- tests/api/test_api.py | 22 ++++++++++++++++++++++ tests/resources/test_collection.py | 21 --------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 7f67e28..482e48a 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -618,6 +618,28 @@ async def test_item_collection_filter_datetime( assert len(resp_json["features"]) == 0 +@pytest.mark.parametrize( + "filter", + [ + "true", + "1=1", + "false", + "1=0", + ], +) +async def test_get_collections_filter( + app_client, load_test_collection, load_test2_collection, filter +): + """ + Test CQL2 filters on the collections endpoint + """ + resp = await app_client.get( + "/collections", + params={"filter": filter}, + ) + assert resp.status_code == 200 + + @pytest.mark.asyncio async def test_bad_collection_queryables( load_test_data, app_client, load_test_collection diff --git a/tests/resources/test_collection.py b/tests/resources/test_collection.py index 2216a2f..013f9ba 100644 --- a/tests/resources/test_collection.py +++ b/tests/resources/test_collection.py @@ -642,24 +642,3 @@ 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", - [ - "true", - "1=1", - "false", - "1=0", - ], -) -async def test_get_collections_filter( - app_client, load_test_collection, load_test2_collection, filter -): - """ - Test CQL2 filters on the collections endpoint - """ - resp = await app_client.get( - "/collections", - params={"filter": filter}, - ) - assert resp.status_code == 200 From 395f2a5ff2576c2de6782a62ae127f3c11852a7b Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Thu, 9 Oct 2025 09:53:08 -0700 Subject: [PATCH 3/4] reorg tests --- tests/api/test_api.py | 22 --------------- tests/resources/test_collection.py | 32 +++++++++++++++++++++ tests/resources/test_item.py | 45 ++++++++++++++---------------- 3 files changed, 53 insertions(+), 46 deletions(-) diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 482e48a..7f67e28 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -618,28 +618,6 @@ async def test_item_collection_filter_datetime( assert len(resp_json["features"]) == 0 -@pytest.mark.parametrize( - "filter", - [ - "true", - "1=1", - "false", - "1=0", - ], -) -async def test_get_collections_filter( - app_client, load_test_collection, load_test2_collection, filter -): - """ - Test CQL2 filters on the collections endpoint - """ - resp = await app_client.get( - "/collections", - params={"filter": filter}, - ) - assert resp.status_code == 200 - - @pytest.mark.asyncio async def test_bad_collection_queryables( load_test_data, app_client, load_test_collection diff --git a/tests/resources/test_collection.py b/tests/resources/test_collection.py index 013f9ba..a9f0d45 100644 --- a/tests/resources/test_collection.py +++ b/tests/resources/test_collection.py @@ -642,3 +642,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), + ("false", "cql2-text", 0), + ("1=0", "cql2-text", 0), + ("true", "cql2-json", 1), + ("1=1", "cql2-json", 1), + ("false", "cql2-json", 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 diff --git a/tests/resources/test_item.py b/tests/resources/test_item.py index 490d652..07b231f 100644 --- a/tests/resources/test_item.py +++ b/tests/resources/test_item.py @@ -1503,7 +1503,20 @@ 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( @@ -1511,32 +1524,16 @@ async def test_get_filter_cql2text(app_client, load_test_data, load_test_collect ) 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( From a261479a6809e98628ff238e37c309e436ccb2fd Mon Sep 17 00:00:00 2001 From: Anthony Lukach Date: Thu, 9 Oct 2025 09:56:04 -0700 Subject: [PATCH 4/4] fix test --- tests/resources/test_collection.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/resources/test_collection.py b/tests/resources/test_collection.py index a9f0d45..08fe364 100644 --- a/tests/resources/test_collection.py +++ b/tests/resources/test_collection.py @@ -1,3 +1,4 @@ +import json from typing import Callable, Optional import pystac @@ -649,12 +650,12 @@ async def test_get_collections_search_offset_1( [ ("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), - ("true", "cql2-json", 1), - ("1=1", "cql2-json", 1), ("false", "cql2-json", 0), - ("1=0", "cql2-json", 0), + (json.dumps({"op": "=", "args": [1.0, 1.0]}), "cql2-json", 0), ], ) async def test_get_collections_filter(