Skip to content

Commit 41cb53f

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
tests: add USE_DATETIME env var tests
- test_use_datetime_true: Verify USE_DATETIME=true finds looks up by datetime, if null then by start/end datetime range - test_use_datetime_false: Verify USE_DATETIME=false only search items with start/end datetime values
1 parent 45588cf commit 41cb53f

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

stac_fastapi/tests/api/test_api.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,3 +1564,93 @@ async def test_search_max_item_limit(
15641564
assert resp.status_code == 200
15651565
resp_json = resp.json()
15661566
assert int(limit) == len(resp_json["features"])
1567+
1568+
1569+
@pytest.mark.asyncio
1570+
async def test_use_datetime_true(
1571+
app_client, load_test_data, txn_client, monkeypatch
1572+
):
1573+
monkeypatch.setenv("USE_DATETIME", "true")
1574+
1575+
test_collection = load_test_data("test_collection.json")
1576+
test_collection["id"] = "test-collection-datetime-true"
1577+
await create_collection(txn_client, test_collection)
1578+
1579+
item = load_test_data("test_item.json")
1580+
1581+
item1 = item.copy()
1582+
item1["id"] = "test-item-datetime"
1583+
item1["collection"] = test_collection["id"]
1584+
item1["properties"]["datetime"] = "2020-01-01T12:00:00Z"
1585+
await create_item(txn_client, item1)
1586+
1587+
item2 = item.copy()
1588+
item2["id"] = "test-item-start-end"
1589+
item2["collection"] = test_collection["id"]
1590+
item1["properties"]["datetime"] = None
1591+
item2["properties"]["start_datetime"] = "2020-01-01T10:00:00Z"
1592+
item2["properties"]["end_datetime"] = "2020-01-01T13:00:00Z"
1593+
await create_item(txn_client, item2)
1594+
1595+
resp = await app_client.post(
1596+
"/search",
1597+
json={
1598+
"datetime": "2020-01-01T12:00:00Z",
1599+
"collections": [test_collection["id"]],
1600+
},
1601+
)
1602+
1603+
assert resp.status_code == 200
1604+
resp_json = resp.json()
1605+
1606+
found_ids = {feature["id"] for feature in resp_json["features"]}
1607+
assert "test-item-datetime" in found_ids
1608+
assert "test-item-start-end" in found_ids
1609+
1610+
1611+
@pytest.mark.asyncio
1612+
async def test_use_datetime_false(
1613+
app_client, load_test_data, txn_client, monkeypatch
1614+
):
1615+
monkeypatch.setenv("USE_DATETIME", "false")
1616+
1617+
test_collection = load_test_data("test_collection.json")
1618+
test_collection["id"] = "test-collection-datetime-false"
1619+
await create_collection(txn_client, test_collection)
1620+
1621+
item = load_test_data("test_item.json")
1622+
1623+
# Item 1: Should NOT be found
1624+
item1 = item.copy()
1625+
item1["id"] = "test-item-datetime-only"
1626+
item1["collection"] = test_collection["id"]
1627+
item1["properties"]["datetime"] = "2020-01-01T12:00:00Z"
1628+
item1["properties"]["start_datetime"] = "2021-01-01T10:00:00Z"
1629+
item1["properties"]["end_datetime"] = "2021-01-01T14:00:00Z"
1630+
await create_item(txn_client, item1)
1631+
1632+
# Item 2: Should be found
1633+
item2 = item.copy()
1634+
item2["id"] = "test-item-start-end-only"
1635+
item2["collection"] = test_collection["id"]
1636+
item2["properties"]["datetime"] = None
1637+
item2["properties"]["start_datetime"] = "2020-01-01T10:00:00Z"
1638+
item2["properties"]["end_datetime"] = "2020-01-01T14:00:00Z"
1639+
await create_item(txn_client, item2)
1640+
1641+
resp = await app_client.post(
1642+
"/search",
1643+
json={
1644+
"datetime": "2020-01-01T12:00:00Z",
1645+
"collections": [test_collection["id"]],
1646+
"limit": 10,
1647+
},
1648+
)
1649+
1650+
assert resp.status_code == 200
1651+
resp_json = resp.json()
1652+
1653+
found_ids = {feature["id"] for feature in resp_json["features"]}
1654+
1655+
assert "test-item-datetime-only" not in found_ids
1656+
assert "test-item-start-end-only" in found_ids

0 commit comments

Comments
 (0)