Skip to content

Commit 395f2a5

Browse files
committed
reorg tests
1 parent 5c55fb4 commit 395f2a5

File tree

3 files changed

+53
-46
lines changed

3 files changed

+53
-46
lines changed

tests/api/test_api.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -618,28 +618,6 @@ async def test_item_collection_filter_datetime(
618618
assert len(resp_json["features"]) == 0
619619

620620

621-
@pytest.mark.parametrize(
622-
"filter",
623-
[
624-
"true",
625-
"1=1",
626-
"false",
627-
"1=0",
628-
],
629-
)
630-
async def test_get_collections_filter(
631-
app_client, load_test_collection, load_test2_collection, filter
632-
):
633-
"""
634-
Test CQL2 filters on the collections endpoint
635-
"""
636-
resp = await app_client.get(
637-
"/collections",
638-
params={"filter": filter},
639-
)
640-
assert resp.status_code == 200
641-
642-
643621
@pytest.mark.asyncio
644622
async def test_bad_collection_queryables(
645623
load_test_data, app_client, load_test_collection

tests/resources/test_collection.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,35 @@ async def test_get_collections_search_offset_1(
642642
prev_link = list(filter(lambda link: link["rel"] == "previous", links))[0]
643643
# offset=0 should not be in the previous link (because it's useless)
644644
assert "offset" not in prev_link["href"]
645+
646+
647+
@pytest.mark.parametrize(
648+
"filter, filter_lang, expected_count",
649+
[
650+
("true", "cql2-text", 1),
651+
("1=1", "cql2-text", 1),
652+
("false", "cql2-text", 0),
653+
("1=0", "cql2-text", 0),
654+
("true", "cql2-json", 1),
655+
("1=1", "cql2-json", 1),
656+
("false", "cql2-json", 0),
657+
("1=0", "cql2-json", 0),
658+
],
659+
)
660+
async def test_get_collections_filter(
661+
app_client,
662+
load_test_collection,
663+
load_test2_collection,
664+
filter,
665+
filter_lang,
666+
expected_count,
667+
):
668+
"""
669+
Test CQL2 filters on the collections endpoint
670+
"""
671+
resp = await app_client.get(
672+
"/collections",
673+
params={"filter": filter, "filter-lang": filter_lang},
674+
)
675+
assert resp.status_code == 200
676+
assert len(resp.json()["collections"]) == expected_count

tests/resources/test_item.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,40 +1503,37 @@ async def test_search_datetime_validation_errors(app_client):
15031503
assert resp.status_code == 400
15041504

15051505

1506-
async def test_get_filter_cql2text(app_client, load_test_data, load_test_collection):
1506+
@pytest.mark.parametrize(
1507+
"cql2_filter,expected_count",
1508+
[
1509+
("true", 1),
1510+
("proj:epsg=32756", 1),
1511+
("proj:epsg=32756 AND collection = 'test-collection'", 1),
1512+
("false", 1), # Bad boolean
1513+
("proj:epsg=11111", 0), # Bad epsg
1514+
("proj:epsg=32756 AND collection = 'bad-collection'", 0), # Bad collection
1515+
],
1516+
)
1517+
async def test_get_filter_cql2text(
1518+
app_client, load_test_data, load_test_collection, cql2_filter, expected_count
1519+
):
15071520
"""Test GET search with cql2-text"""
15081521
test_item = load_test_data("test_item.json")
15091522
resp = await app_client.post(
15101523
f"/collections/{test_item['collection']}/items", json=test_item
15111524
)
15121525
assert resp.status_code == 201
15131526

1514-
epsg = test_item["properties"]["proj:epsg"]
1515-
collection = test_item["collection"]
1516-
1517-
filter = f"proj:epsg={epsg} AND collection = '{collection}'"
1518-
params = {"filter": filter, "filter-lang": "cql2-text"}
1519-
resp = await app_client.get("/search", params=params)
1520-
resp_json = resp.json()
1521-
assert len(resp.json()["features"]) == 1
1522-
assert (
1523-
resp_json["features"][0]["properties"]["proj:epsg"]
1524-
== test_item["properties"]["proj:epsg"]
1525-
)
1526-
1527-
filter = f"proj:epsg={epsg + 1} AND collection = '{collection}'"
1528-
params = {"filter": filter, "filter-lang": "cql2-text"}
1529-
resp = await app_client.get("/search", params=params)
1530-
resp_json = resp.json()
1531-
assert len(resp.json()["features"]) == 0
1532-
1533-
filter = f"proj:epsg={epsg}"
1534-
params = {"filter": filter, "filter-lang": "cql2-text"}
15351527
resp = await app_client.get(
1536-
f"/collections/{test_item['collection']}/items", params=params
1528+
"/search", params={"filter": cql2_filter, "filter-lang": "cql2-text"}
15371529
)
15381530
resp_json = resp.json()
1539-
assert len(resp.json()["features"]) == 1
1531+
assert len(resp.json()["features"]) == expected_count
1532+
if expected_count == 1:
1533+
assert (
1534+
resp_json["features"][0]["properties"]["proj:epsg"]
1535+
== test_item["properties"]["proj:epsg"]
1536+
)
15401537

15411538

15421539
async def test_item_merge_raster_bands(

0 commit comments

Comments
 (0)