Skip to content

Commit e08f1cd

Browse files
committed
update test
1 parent 345a0af commit e08f1cd

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

stac_fastapi/tests/api/test_api.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import pytest
77

8+
from stac_fastapi.types.errors import ConflictError
9+
810
from ..conftest import create_collection, create_item
911

1012
ROUTES = {
@@ -635,53 +637,47 @@ async def test_search_line_string_intersects(app_client, ctx):
635637
@pytest.mark.parametrize(
636638
"value, expected",
637639
[
638-
(32767, 1), # Short Limit,
640+
(32767, 1), # Short Limit
639641
(2147483647, 1), # Int Limit
640-
(2147483647 + 5000, 1), # Above int Limit
641-
(21474836470, 1), # Above int Limit
642-
# This value still fails to return 1
643-
# Commenting out
644-
# (9223372036854775807, 1),
642+
(2147483647 + 5000, 1), # Above Int Limit
643+
(21474836470, 1), # Above Int Limit
645644
],
646645
)
647646
async def test_big_int_eo_search(
648647
app_client, txn_client, test_item, test_collection, value, expected
649648
):
650-
651-
random_str = "".join(random.choice("abcdef") for i in range(random.randint(1, 5)))
649+
random_str = "".join(random.choice("abcdef") for _ in range(5))
652650
collection_id = f"test-collection-eo-{random_str}"
653651

654-
test_big_int_item = test_item
655-
del test_big_int_item["properties"]["eo:bands"]
656-
test_big_int_item["collection"] = collection_id
657-
test_big_int_collection = test_collection
658-
test_big_int_collection["id"] = collection_id
659-
660-
# type number
661-
attr = "eo:full_width_half_max"
662-
663-
stac_extensions = [
664-
"https://stac-extensions.github.io/eo/v2.0.0/schema.json",
652+
test_collection["id"] = collection_id
653+
test_collection["stac_extensions"] = [
654+
"https://stac-extensions.github.io/eo/v2.0.0/schema.json"
665655
]
666656

667-
test_collection["stac_extensions"] = stac_extensions
657+
test_item["collection"] = collection_id
658+
test_item["stac_extensions"] = test_collection["stac_extensions"]
668659

669-
test_item["stac_extensions"] = stac_extensions
660+
# Remove "eo:bands" to simplify the test
661+
del test_item["properties"]["eo:bands"]
670662

671-
await create_collection(txn_client, test_collection)
663+
# Attribute to test
664+
attr = "eo:full_width_half_max"
672665

673-
for val in [
674-
value,
675-
value + random.randint(10, 1010),
676-
value - random.randint(10, 1010),
677-
]:
666+
try:
667+
await create_collection(txn_client, test_collection)
668+
except ConflictError:
669+
pass
670+
671+
# Create items with deterministic offsets
672+
for val in [value, value + 100, value - 100]:
678673
item = deepcopy(test_item)
679674
item["id"] = str(uuid.uuid4())
680675
item["properties"][attr] = val
681676
await create_item(txn_client, item)
682677

678+
# Search for the exact value
683679
params = {
684-
"collections": [item["collection"]],
680+
"collections": [collection_id],
685681
"filter": {
686682
"args": [
687683
{
@@ -697,5 +693,8 @@ async def test_big_int_eo_search(
697693
}
698694
resp = await app_client.post("/search", json=params)
699695
resp_json = resp.json()
700-
results = set([x["properties"][attr] for x in resp_json["features"]])
696+
697+
# Validate results
698+
results = {x["properties"][attr] for x in resp_json["features"]}
701699
assert len(results) == expected
700+
assert results == {value}

0 commit comments

Comments
 (0)