@@ -1750,90 +1750,43 @@ async def test_item_asset_change(app_client, load_test_data):
17501750 )
17511751 assert len (resp .json ()["features" ]) == 1
17521752 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- )
1758-
1759- # remove item_assets in collection
1760- operations = [{"op" : "remove" , "path" : "/item_assets" }]
1761- resp = await app_client .patch (f"/collections/{ collection_id } " , json = operations )
1762- assert resp .status_code == 200
1763-
1764- # make sure item_assets is not in collection response
1765- resp = await app_client .get (f"/collections/{ collection_id } " )
1766- assert resp .status_code == 200
1767- assert "item_assets" not in resp .json ()
17681753
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
1771- resp = await app_client .get (
1772- f"/collections/{ collection_id } /items" , params = {"limit" : 1 }
1773- )
1774- assert len (resp .json ()["features" ]) == 1
1775- assert resp .status_code == 200
1754+ # NOTE: API or PgSTAC Hydration we should get the same values as original Item
17761755 assert (
17771756 test_item ["assets" ]["red" ]["raster:bands" ]
17781757 == resp .json ()["features" ][0 ]["assets" ]["red" ]["raster:bands" ]
17791758 )
17801759
1760+ # NOTE: `description` is not in the item body but in the collection's item-assets
1761+ # because it's not in the original item it won't be hydrated
1762+ assert not resp .json ()["features" ][0 ]["assets" ]["qa_pixel" ].get ("description" )
17811763
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
1764+ ###########################################################################
1765+ # Remove item_assets in collection
18211766 operations = [{"op" : "remove" , "path" : "/item_assets" }]
18221767 resp = await app_client .patch (f"/collections/{ collection_id } " , json = operations )
18231768 assert resp .status_code == 200
18241769
1825- # make sure item_assets is not in collection response
1770+ # Make sure item_assets is not in collection response
18261771 resp = await app_client .get (f"/collections/{ collection_id } " )
18271772 assert resp .status_code == 200
18281773 assert "item_assets" not in resp .json ()
1774+ ###########################################################################
18291775
18301776 resp = await app_client .get (
18311777 f"/collections/{ collection_id } /items" , params = {"limit" : 1 }
18321778 )
18331779 assert len (resp .json ()["features" ]) == 1
18341780 assert resp .status_code == 200
1835- assert resp .json ()["features" ][0 ]["assets" ]["green" ]["raster:bands" ] == "𒍟※"
18361781
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" ] == "𒍟※"
1782+ # NOTE: here we should only get `scale`, `offset` and `spatial_resolution`
1783+ # because the other values were stripped on ingestion (dehydration is a default in PgSTAC)
1784+ # scale and offset are no in item-asset and spatial_resolution is different, so the value in the item body is kept
1785+ assert ["scale" , "offset" , "spatial_resolution" ] == list (
1786+ resp .json ()["features" ][0 ]["assets" ]["red" ]["raster:bands" ][0 ]
1787+ )
1788+
1789+ # NOTE: `description` is not in the original item but in the collection's item-assets
1790+ # We get "𒍟※" because PgSTAC set it when ingesting (`description`is item-assets)
1791+ # because we removed item-assets, pgstac cannot hydrate this field, and thus return "𒍟※"
1792+ assert resp .json ()["features" ][0 ]["assets" ]["qa_pixel" ]["description" ] == "𒍟※"
0 commit comments