@@ -1726,6 +1726,10 @@ async def test_item_search_freetext(app_client, load_test_data, load_test_collec
17261726
17271727@pytest .mark .asyncio
17281728async def test_item_asset_change (app_client , load_test_data ):
1729+ """Check that changing item_assets in collection does
1730+ not affect existing items if hydration should not occur.
1731+
1732+ """
17291733 # load collection
17301734 data = load_test_data ("test2_collection.json" )
17311735 collection_id = data ["id" ]
@@ -1746,6 +1750,11 @@ async def test_item_asset_change(app_client, load_test_data):
17461750 )
17471751 assert len (resp .json ()["features" ]) == 1
17481752 assert resp .status_code == 200
1753+ # NOTE: Hydration or Not we should get the same values as original Item
1754+ assert (
1755+ test_item ["assets" ]["red" ]["raster:bands" ]
1756+ == resp .json ()["features" ][0 ]["assets" ]["red" ]["raster:bands" ]
1757+ )
17491758
17501759 # remove item_assets in collection
17511760 operations = [{"op" : "remove" , "path" : "/item_assets" }]
@@ -1757,8 +1766,74 @@ async def test_item_asset_change(app_client, load_test_data):
17571766 assert resp .status_code == 200
17581767 assert "item_assets" not in resp .json ()
17591768
1769+ # NOTE: Should Fail
1770+ # For some reason we get the part not present in the Collection's item_assets but not originaly from the Item
17601771 resp = await app_client .get (
17611772 f"/collections/{ collection_id } /items" , params = {"limit" : 1 }
17621773 )
17631774 assert len (resp .json ()["features" ]) == 1
17641775 assert resp .status_code == 200
1776+ assert (
1777+ test_item ["assets" ]["red" ]["raster:bands" ]
1778+ == resp .json ()["features" ][0 ]["assets" ]["red" ]["raster:bands" ]
1779+ )
1780+
1781+
1782+ @pytest .mark .asyncio
1783+ async def test_item_asset_change_hydration (app_client , load_test_data ):
1784+ """Test hydration process."""
1785+ # Only test when Hydration is enabled
1786+ if not app_client ._transport .app .state .settings .use_api_hydrate :
1787+ return
1788+
1789+ # load collection
1790+ data = load_test_data ("test2_collection.json" )
1791+ collection_id = data ["id" ]
1792+
1793+ resp = await app_client .post ("/collections" , json = data )
1794+ assert "item_assets" in data
1795+ assert resp .status_code == 201
1796+ assert "item_assets" in resp .json ()
1797+
1798+ # load items
1799+ test_item = load_test_data ("test2_item.json" )
1800+ resp = await app_client .post (f"/collections/{ collection_id } /items" , json = test_item )
1801+ assert resp .status_code == 201
1802+
1803+ # check list of items
1804+ resp = await app_client .get (
1805+ f"/collections/{ collection_id } /items" , params = {"limit" : 1 }
1806+ )
1807+ assert len (resp .json ()["features" ]) == 1
1808+ assert resp .status_code == 200
1809+ # The items should be the same
1810+ # When hydrated we should get the value from the collection's item_assets
1811+ assert (
1812+ resp .json ()["features" ][0 ]["assets" ]["green" ]["raster:bands" ]
1813+ == data ["item_assets" ]["green" ]["raster:bands" ]
1814+ )
1815+
1816+ # TODO: Check if OK
1817+ # We don't have `"raster:bands"` for `nir08` asset in the original Items body
1818+ assert resp .json ()["features" ][0 ]["assets" ]["nir08" ]["raster:bands" ]
1819+
1820+ # remove item_assets in collection
1821+ operations = [{"op" : "remove" , "path" : "/item_assets" }]
1822+ resp = await app_client .patch (f"/collections/{ collection_id } " , json = operations )
1823+ assert resp .status_code == 200
1824+
1825+ # make sure item_assets is not in collection response
1826+ resp = await app_client .get (f"/collections/{ collection_id } " )
1827+ assert resp .status_code == 200
1828+ assert "item_assets" not in resp .json ()
1829+
1830+ resp = await app_client .get (
1831+ f"/collections/{ collection_id } /items" , params = {"limit" : 1 }
1832+ )
1833+ assert len (resp .json ()["features" ]) == 1
1834+ assert resp .status_code == 200
1835+ assert resp .json ()["features" ][0 ]["assets" ]["green" ]["raster:bands" ] == "𒍟※"
1836+
1837+ # TODO: Check if OK
1838+ # We don't have `"raster:bands"` for `nir08` asset in the original Items body but for some reason we get "𒍟※"
1839+ assert resp .json ()["features" ][0 ]["assets" ]["nir08" ]["raster:bands" ] == "𒍟※"
0 commit comments