Skip to content

Commit 3392afb

Browse files
committed
move item collection fields extension api tests
1 parent 4f2ff6d commit 3392afb

File tree

2 files changed

+68
-68
lines changed

2 files changed

+68
-68
lines changed

stac_fastapi/tests/api/test_api.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -228,74 +228,6 @@ async def test_app_fields_extension_return_all_properties(
228228
assert feature["properties"][expected_prop] == expected_value
229229

230230

231-
@pytest.mark.asyncio
232-
async def test_app_fields_extension_collection_items(app_client, ctx, txn_client):
233-
resp = await app_client.get(
234-
"/collections/test-collection/items",
235-
params={"fields": "+properties.datetime"},
236-
)
237-
assert resp.status_code == 200
238-
resp_json = resp.json()
239-
assert list(resp_json["features"][0]["properties"]) == ["datetime"]
240-
241-
242-
@pytest.mark.asyncio
243-
async def test_app_fields_extension_no_properties_get_collection_items(
244-
app_client, ctx, txn_client
245-
):
246-
resp = await app_client.get(
247-
"/collections/test-collection/items", params={"fields": "-properties"}
248-
)
249-
assert resp.status_code == 200
250-
resp_json = resp.json()
251-
assert "properties" not in resp_json["features"][0]
252-
253-
254-
@pytest.mark.asyncio
255-
async def test_app_fields_extension_no_null_fields_collection_items(
256-
app_client, ctx, txn_client
257-
):
258-
resp = await app_client.get("/collections/test-collection/items")
259-
assert resp.status_code == 200
260-
resp_json = resp.json()
261-
# check if no null fields: https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166
262-
for feature in resp_json["features"]:
263-
# assert "bbox" not in feature["geometry"]
264-
for link in feature["links"]:
265-
assert all(a not in link or link[a] is not None for a in ("title", "asset"))
266-
for asset in feature["assets"]:
267-
assert all(
268-
a not in asset or asset[a] is not None
269-
for a in ("start_datetime", "created")
270-
)
271-
272-
273-
@pytest.mark.asyncio
274-
async def test_app_fields_extension_return_all_properties_collection_items(
275-
app_client, ctx, txn_client, load_test_data
276-
):
277-
item = load_test_data("test_item.json")
278-
resp = await app_client.get(
279-
"/collections/test-collection/items",
280-
params={"collections": ["test-collection"], "fields": "properties"},
281-
)
282-
assert resp.status_code == 200
283-
resp_json = resp.json()
284-
feature = resp_json["features"][0]
285-
assert len(feature["properties"]) >= len(item["properties"])
286-
for expected_prop, expected_value in item["properties"].items():
287-
if expected_prop in (
288-
"datetime",
289-
"start_datetime",
290-
"end_datetime",
291-
"created",
292-
"updated",
293-
):
294-
assert feature["properties"][expected_prop][0:19] == expected_value[0:19]
295-
else:
296-
assert feature["properties"][expected_prop] == expected_value
297-
298-
299231
@pytest.mark.asyncio
300232
async def test_app_query_extension_gt(app_client, ctx):
301233
params = {"query": {"proj:epsg": {"gt": ctx.item["properties"]["proj:epsg"]}}}

stac_fastapi/tests/api/test_api_item_collection.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,71 @@ async def test_item_collection_filter_by_nonexistent_id(app_client, ctx, txn_cli
190190
assert (
191191
len(resp_json["features"]) == 0
192192
), f"Expected no items with ID {non_existent_id}, but found {len(resp_json['features'])} matches"
193+
194+
195+
@pytest.mark.asyncio
196+
async def test_item_collection_fields_extension(app_client, ctx, txn_client):
197+
resp = await app_client.get(
198+
"/collections/test-collection/items",
199+
params={"fields": "+properties.datetime"},
200+
)
201+
assert resp.status_code == 200
202+
resp_json = resp.json()
203+
assert list(resp_json["features"][0]["properties"]) == ["datetime"]
204+
205+
206+
@pytest.mark.asyncio
207+
async def test_item_collection_fields_extension_no_properties_get(
208+
app_client, ctx, txn_client
209+
):
210+
resp = await app_client.get(
211+
"/collections/test-collection/items", params={"fields": "-properties"}
212+
)
213+
assert resp.status_code == 200
214+
resp_json = resp.json()
215+
assert "properties" not in resp_json["features"][0]
216+
217+
218+
@pytest.mark.asyncio
219+
async def test_item_collection_fields_extension_no_null_fields(
220+
app_client, ctx, txn_client
221+
):
222+
resp = await app_client.get("/collections/test-collection/items")
223+
assert resp.status_code == 200
224+
resp_json = resp.json()
225+
# check if no null fields: https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/166
226+
for feature in resp_json["features"]:
227+
# assert "bbox" not in feature["geometry"]
228+
for link in feature["links"]:
229+
assert all(a not in link or link[a] is not None for a in ("title", "asset"))
230+
for asset in feature["assets"]:
231+
assert all(
232+
a not in asset or asset[a] is not None
233+
for a in ("start_datetime", "created")
234+
)
235+
236+
237+
@pytest.mark.asyncio
238+
async def test_item_collection_fields_extension_return_all_properties(
239+
app_client, ctx, txn_client, load_test_data
240+
):
241+
item = load_test_data("test_item.json")
242+
resp = await app_client.get(
243+
"/collections/test-collection/items",
244+
params={"collections": ["test-collection"], "fields": "properties"},
245+
)
246+
assert resp.status_code == 200
247+
resp_json = resp.json()
248+
feature = resp_json["features"][0]
249+
assert len(feature["properties"]) >= len(item["properties"])
250+
for expected_prop, expected_value in item["properties"].items():
251+
if expected_prop in (
252+
"datetime",
253+
"start_datetime",
254+
"end_datetime",
255+
"created",
256+
"updated",
257+
):
258+
assert feature["properties"][expected_prop][0:19] == expected_value[0:19]
259+
else:
260+
assert feature["properties"][expected_prop] == expected_value

0 commit comments

Comments
 (0)