@@ -1794,3 +1794,62 @@ async def test_item_asset_change(app_client, load_test_data):
17941794 # We get "𒍟※" because PgSTAC set it when ingesting (`description`is item-assets)
17951795 # because we removed item-assets, pgstac cannot hydrate this field, and thus return "𒍟※"
17961796 assert resp .json ()["features" ][0 ]["assets" ]["qa_pixel" ]["description" ] == "𒍟※"
1797+
1798+
1799+ @pytest .mark .asyncio
1800+ async def test_item_asset_change_two (app_client_no_ext , load_test_data ):
1801+ """Check what happens after changing item_assets in collection"""
1802+ # load collection without item_assets
1803+ data = load_test_data ("test2_collection.json" )
1804+ collection_id = data ["id" ]
1805+ _ = data .pop ("item_assets" )
1806+
1807+ resp = await app_client_no_ext .post ("/collections" , json = data )
1808+ assert resp .status_code == 201
1809+ assert "item_assets" not in resp .json ()
1810+
1811+ # load items
1812+ test_item = load_test_data ("test2_item.json" )
1813+ red = test_item ["assets" ].pop ("red" )
1814+ # add only one asset
1815+ test_item ["assets" ] = {"red" : red }
1816+
1817+ resp = await app_client_no_ext .post (
1818+ f"/collections/{ collection_id } /items" , json = test_item
1819+ )
1820+ assert resp .status_code == 201
1821+
1822+ # check list of items
1823+ resp = await app_client_no_ext .get (
1824+ f"/collections/{ collection_id } /items" , params = {"limit" : 1 }
1825+ )
1826+ assert resp .status_code == 200
1827+ assert len (resp .json ()["features" ]) == 1
1828+ assert list (resp .json ()["features" ][0 ]["assets" ]) == ["red" ]
1829+
1830+ # Patch the collection to add item_assets
1831+ item_assets = {
1832+ "blue" : {"description" : "30m Cloud free composite of the HLS blue band." }
1833+ }
1834+
1835+ operations = [{"op" : "add" , "path" : "/item_assets" , "value" : item_assets }]
1836+ resp = await app_client_no_ext .patch (f"/collections/{ collection_id } " , json = operations )
1837+ assert resp .status_code == 200
1838+
1839+ # Make sure item_assets IS in collection response
1840+ resp = await app_client_no_ext .get (f"/collections/{ collection_id } " )
1841+ assert resp .status_code == 200
1842+ assert "item_assets" in resp .json ()
1843+
1844+ resp = await app_client_no_ext .get (
1845+ f"/collections/{ collection_id } /items" , params = {"limit" : 1 }
1846+ )
1847+ assert len (resp .json ()["features" ]) == 1
1848+ assert resp .status_code == 200
1849+
1850+ # Because we now have `blue` in item_assets, it will be added in the item
1851+ assert list (resp .json ()["features" ][0 ]["assets" ]) == ["red" , "blue" ]
1852+ assert (
1853+ resp .json ()["features" ][0 ]["assets" ]["blue" ]["description" ]
1854+ == "30m Cloud free composite of the HLS blue band."
1855+ )
0 commit comments