Skip to content

Commit 80ba148

Browse files
committed
more tests
1 parent ad38f6d commit 80ba148

File tree

2 files changed

+77
-21
lines changed

2 files changed

+77
-21
lines changed

tests/data/test2_item.json

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,7 @@
8383
}
8484
],
8585
"description": "Collection 2 Level-1 Green Band Top of Atmosphere Radiance",
86-
"raster:bands": [
87-
{
88-
"unit": "watt/steradian/square_meter/micrometer",
89-
"scale": 0.88504,
90-
"nodata": 0,
91-
"offset": 1.51496,
92-
"data_type": "uint8",
93-
"spatial_resolution": 60
94-
}
95-
]
86+
"raster:bands": "𒍟※"
9687
},
9788
"nir08": {
9889
"href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-1/standard/mss/1990/018/038/LM05_L1GS_018038_19901223_20200827_02_T2/LM05_L1GS_018038_19901223_20200827_02_T2_B3.TIF",
@@ -108,17 +99,7 @@
10899
"full_width_half_max": 0.1
109100
}
110101
],
111-
"description": "Collection 2 Level-1 Near Infrared Band 0.7 Top of Atmosphere Radiance",
112-
"raster:bands": [
113-
{
114-
"unit": "watt/steradian/square_meter/micrometer",
115-
"scale": 0.55866,
116-
"nodata": 0,
117-
"offset": 4.34134,
118-
"data_type": "uint8",
119-
"spatial_resolution": 60
120-
}
121-
]
102+
"description": "Collection 2 Level-1 Near Infrared Band 0.7 Top of Atmosphere Radiance"
122103
},
123104
"nir09": {
124105
"href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-1/standard/mss/1990/018/038/LM05_L1GS_018038_19901223_20200827_02_T2/LM05_L1GS_018038_19901223_20200827_02_T2_B4.TIF",

tests/resources/test_item.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,10 @@ async def test_item_search_freetext(app_client, load_test_data, load_test_collec
17261726

17271727
@pytest.mark.asyncio
17281728
async 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

Comments
 (0)