@@ -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