Skip to content

Commit 79e97aa

Browse files
author
Chris Arderne
committed
Add item_collection bbox/datetime tests
1 parent 5aa95bd commit 79e97aa

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

stac_fastapi/pgstac/tests/api/test_api.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,51 @@ async def test_collection_queryables(load_test_data, app_client, load_test_colle
415415
assert "properties" in q
416416
assert "id" in q["properties"]
417417
assert "eo:cloud_cover" in q["properties"]
418+
419+
420+
@pytest.mark.asyncio
421+
async def test_item_collection_filter_bbox(
422+
load_test_data, app_client, load_test_collection
423+
):
424+
coll = load_test_collection
425+
first_item = load_test_data("test_item.json")
426+
resp = await app_client.post(f"/collections/{coll.id}/items", json=first_item)
427+
assert resp.status_code == 200
428+
429+
bbox = "100,-50,170,-20"
430+
resp = await app_client.get(f"/collections/{coll.id}/items", params={"bbox": bbox})
431+
assert resp.status_code == 200
432+
resp_json = resp.json()
433+
assert len(resp_json["features"]) == 1
434+
435+
bbox = "1,2,3,4"
436+
resp = await app_client.get(f"/collections/{coll.id}/items", params={"bbox": bbox})
437+
assert resp.status_code == 200
438+
resp_json = resp.json()
439+
assert len(resp_json["features"]) == 0
440+
441+
442+
@pytest.mark.asyncio
443+
async def test_item_collection_filter_datetime(
444+
load_test_data, app_client, load_test_collection
445+
):
446+
coll = load_test_collection
447+
first_item = load_test_data("test_item.json")
448+
resp = await app_client.post(f"/collections/{coll.id}/items", json=first_item)
449+
assert resp.status_code == 200
450+
451+
datetime_range = "2020-01-01T00:00:00.00Z/.."
452+
resp = await app_client.get(
453+
f"/collections/{coll.id}/items", params={"datetime": datetime_range}
454+
)
455+
assert resp.status_code == 200
456+
resp_json = resp.json()
457+
assert len(resp_json["features"]) == 1
458+
459+
datetime_range = "2018-01-01T00:00:00.00Z/2019-01-01T00:00:00.00Z"
460+
resp = await app_client.get(
461+
f"/collections/{coll.id}/items", params={"datetime": datetime_range}
462+
)
463+
assert resp.status_code == 200
464+
resp_json = resp.json()
465+
assert len(resp_json["features"]) == 0

stac_fastapi/sqlalchemy/tests/api/test_api.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,49 @@ def test_app_search_response_duplicate_forwarded_headers(
434434
for feature in resp.json()["features"]:
435435
for link in feature["links"]:
436436
assert link["href"].startswith("https://testserver:1234/")
437+
438+
439+
def test_item_collection_filter_bbox(load_test_data, app_client, postgres_transactions):
440+
item = load_test_data("test_item.json")
441+
collection = item["collection"]
442+
postgres_transactions.create_item(
443+
item["collection"], item, request=MockStarletteRequest
444+
)
445+
446+
bbox = "100,-50,170,-20"
447+
resp = app_client.get(f"/collections/{collection}/items", params={"bbox": bbox})
448+
assert resp.status_code == 200
449+
resp_json = resp.json()
450+
assert len(resp_json["features"]) == 1
451+
452+
bbox = "1,2,3,4"
453+
resp = app_client.get(f"/collections/{collection}/items", params={"bbox": bbox})
454+
assert resp.status_code == 200
455+
resp_json = resp.json()
456+
assert len(resp_json["features"]) == 0
457+
458+
459+
def test_item_collection_filter_datetime(
460+
load_test_data, app_client, postgres_transactions
461+
):
462+
item = load_test_data("test_item.json")
463+
collection = item["collection"]
464+
postgres_transactions.create_item(
465+
item["collection"], item, request=MockStarletteRequest
466+
)
467+
468+
datetime_range = "2020-01-01T00:00:00.00Z/.."
469+
resp = app_client.get(
470+
f"/collections/{collection}/items", params={"datetime": datetime_range}
471+
)
472+
assert resp.status_code == 200
473+
resp_json = resp.json()
474+
assert len(resp_json["features"]) == 1
475+
476+
datetime_range = "2018-01-01T00:00:00.00Z/2019-01-01T00:00:00.00Z"
477+
resp = app_client.get(
478+
f"/collections/{collection}/items", params={"datetime": datetime_range}
479+
)
480+
assert resp.status_code == 200
481+
resp_json = resp.json()
482+
assert len(resp_json["features"]) == 0

0 commit comments

Comments
 (0)