From 79004275c69404cc6a83a8f2777ef35ff4d1ed29 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Mon, 30 Jan 2023 23:00:33 +0300 Subject: [PATCH 1/3] add ctx --- .../elasticsearch/tests/resources/test_item.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stac_fastapi/elasticsearch/tests/resources/test_item.py b/stac_fastapi/elasticsearch/tests/resources/test_item.py index 6e0d9b94..91fe709b 100644 --- a/stac_fastapi/elasticsearch/tests/resources/test_item.py +++ b/stac_fastapi/elasticsearch/tests/resources/test_item.py @@ -260,7 +260,7 @@ async def test_pagination(app_client, load_test_data): assert second_page["context"]["returned"] == 3 -async def test_item_timestamps(app_client, ctx, load_test_data): +async def test_item_timestamps(app_client, ctx): """Test created and updated timestamps (common metadata)""" # start_time = now_to_rfc3339_str() @@ -335,7 +335,7 @@ async def test_item_search_temporal_query_post(app_client, ctx): assert resp_json["features"][0]["id"] == test_item["id"] -async def test_item_search_temporal_window_post(app_client, load_test_data, ctx): +async def test_item_search_temporal_window_post(app_client, ctx): """Test POST search with two-tailed spatio-temporal query (core)""" test_item = ctx.item @@ -649,7 +649,7 @@ async def test_pagination_token_idempotent(app_client, ctx, txn_client): ] -async def test_field_extension_get_includes(app_client): +async def test_field_extension_get_includes(app_client, ctx): """Test GET search with included fields (fields extension)""" params = {"fields": "+properties.proj:epsg,+properties.gsd"} resp = await app_client.get("/search", params=params) @@ -657,7 +657,7 @@ async def test_field_extension_get_includes(app_client): assert not set(feat_properties) - {"proj:epsg", "gsd", "datetime"} -async def test_field_extension_get_excludes(app_client): +async def test_field_extension_get_excludes(app_client, ctx): """Test GET search with included fields (fields extension)""" params = {"fields": "-properties.proj:epsg,-properties.gsd"} resp = await app_client.get("/search", params=params) @@ -666,7 +666,7 @@ async def test_field_extension_get_excludes(app_client): assert "gsd" not in resp_json["features"][0]["properties"].keys() -async def test_field_extension_post(app_client): +async def test_field_extension_post(app_client, ctx): """Test POST search with included and excluded fields (fields extension)""" body = { "fields": { @@ -685,7 +685,7 @@ async def test_field_extension_post(app_client): } -async def test_field_extension_exclude_and_include(app_client, load_test_data): +async def test_field_extension_exclude_and_include(app_client, ctx): """Test POST search including/excluding same field (fields extension)""" body = { "fields": { @@ -699,7 +699,7 @@ async def test_field_extension_exclude_and_include(app_client, load_test_data): assert "eo:cloud_cover" not in resp_json["features"][0]["properties"] -async def test_field_extension_exclude_default_includes(app_client, load_test_data): +async def test_field_extension_exclude_default_includes(app_client, ctx): """Test POST search excluding a forbidden field (fields extension)""" body = {"fields": {"exclude": ["gsd"]}} From e4b77643128f64e0b7a841515cfa43ddf23ceb45 Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Fri, 3 Feb 2023 15:38:31 +0300 Subject: [PATCH 2/3] use ctx.item id --- .../elasticsearch/tests/resources/test_item.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stac_fastapi/elasticsearch/tests/resources/test_item.py b/stac_fastapi/elasticsearch/tests/resources/test_item.py index 91fe709b..5cf3e94b 100644 --- a/stac_fastapi/elasticsearch/tests/resources/test_item.py +++ b/stac_fastapi/elasticsearch/tests/resources/test_item.py @@ -651,7 +651,8 @@ async def test_pagination_token_idempotent(app_client, ctx, txn_client): async def test_field_extension_get_includes(app_client, ctx): """Test GET search with included fields (fields extension)""" - params = {"fields": "+properties.proj:epsg,+properties.gsd"} + test_item = ctx.item + params = {"ids": [test_item["id"]], "fields": "+properties.proj:epsg,+properties.gsd"} resp = await app_client.get("/search", params=params) feat_properties = resp.json()["features"][0]["properties"] assert not set(feat_properties) - {"proj:epsg", "gsd", "datetime"} @@ -659,7 +660,8 @@ async def test_field_extension_get_includes(app_client, ctx): async def test_field_extension_get_excludes(app_client, ctx): """Test GET search with included fields (fields extension)""" - params = {"fields": "-properties.proj:epsg,-properties.gsd"} + test_item = ctx.item + params = {"ids": [test_item["id"]], "fields": "-properties.proj:epsg,-properties.gsd"} resp = await app_client.get("/search", params=params) resp_json = resp.json() assert "proj:epsg" not in resp_json["features"][0]["properties"].keys() @@ -668,7 +670,9 @@ async def test_field_extension_get_excludes(app_client, ctx): async def test_field_extension_post(app_client, ctx): """Test POST search with included and excluded fields (fields extension)""" + test_item = ctx.item body = { + "ids": [test_item["id"]], "fields": { "exclude": ["assets.B1"], "include": ["properties.eo:cloud_cover", "properties.orientation"], @@ -687,7 +691,9 @@ async def test_field_extension_post(app_client, ctx): async def test_field_extension_exclude_and_include(app_client, ctx): """Test POST search including/excluding same field (fields extension)""" + test_item = ctx.item body = { + "ids": [test_item["id"]], "fields": { "exclude": ["properties.eo:cloud_cover"], "include": ["properties.eo:cloud_cover"], @@ -701,7 +707,11 @@ async def test_field_extension_exclude_and_include(app_client, ctx): async def test_field_extension_exclude_default_includes(app_client, ctx): """Test POST search excluding a forbidden field (fields extension)""" - body = {"fields": {"exclude": ["gsd"]}} + test_item = ctx.item + body = { + "ids": [test_item["id"]], + "fields": {"exclude": ["gsd"]} + } resp = await app_client.post("/search", json=body) resp_json = resp.json() From 4a8938fda3aecee22f83bbd226f9427a1406cf8f Mon Sep 17 00:00:00 2001 From: jonhealy1 Date: Fri, 3 Feb 2023 15:43:38 +0300 Subject: [PATCH 3/3] pre-commit --- .../tests/resources/test_item.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/stac_fastapi/elasticsearch/tests/resources/test_item.py b/stac_fastapi/elasticsearch/tests/resources/test_item.py index 5cf3e94b..6f9d37ca 100644 --- a/stac_fastapi/elasticsearch/tests/resources/test_item.py +++ b/stac_fastapi/elasticsearch/tests/resources/test_item.py @@ -652,7 +652,10 @@ async def test_pagination_token_idempotent(app_client, ctx, txn_client): async def test_field_extension_get_includes(app_client, ctx): """Test GET search with included fields (fields extension)""" test_item = ctx.item - params = {"ids": [test_item["id"]], "fields": "+properties.proj:epsg,+properties.gsd"} + params = { + "ids": [test_item["id"]], + "fields": "+properties.proj:epsg,+properties.gsd", + } resp = await app_client.get("/search", params=params) feat_properties = resp.json()["features"][0]["properties"] assert not set(feat_properties) - {"proj:epsg", "gsd", "datetime"} @@ -661,7 +664,10 @@ async def test_field_extension_get_includes(app_client, ctx): async def test_field_extension_get_excludes(app_client, ctx): """Test GET search with included fields (fields extension)""" test_item = ctx.item - params = {"ids": [test_item["id"]], "fields": "-properties.proj:epsg,-properties.gsd"} + params = { + "ids": [test_item["id"]], + "fields": "-properties.proj:epsg,-properties.gsd", + } resp = await app_client.get("/search", params=params) resp_json = resp.json() assert "proj:epsg" not in resp_json["features"][0]["properties"].keys() @@ -676,7 +682,7 @@ async def test_field_extension_post(app_client, ctx): "fields": { "exclude": ["assets.B1"], "include": ["properties.eo:cloud_cover", "properties.orientation"], - } + }, } resp = await app_client.post("/search", json=body) @@ -697,7 +703,7 @@ async def test_field_extension_exclude_and_include(app_client, ctx): "fields": { "exclude": ["properties.eo:cloud_cover"], "include": ["properties.eo:cloud_cover"], - } + }, } resp = await app_client.post("/search", json=body) @@ -708,10 +714,7 @@ async def test_field_extension_exclude_and_include(app_client, ctx): async def test_field_extension_exclude_default_includes(app_client, ctx): """Test POST search excluding a forbidden field (fields extension)""" test_item = ctx.item - body = { - "ids": [test_item["id"]], - "fields": {"exclude": ["gsd"]} - } + body = {"ids": [test_item["id"]], "fields": {"exclude": ["gsd"]}} resp = await app_client.post("/search", json=body) resp_json = resp.json()