diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e24f49a9..3cdc2d7d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ ### Fixed +- `Collection.from_dict` and `Collection.from_file` now correctly construct `Asset` objects. + ### Removed ## [1.0.0-beta.2] diff --git a/pystac/collection.py b/pystac/collection.py index ababda2ae..7f7e7b0b6 100644 --- a/pystac/collection.py +++ b/pystac/collection.py @@ -715,7 +715,9 @@ def from_dict( if assets is not None: for asset_key, asset_dict in assets.items(): - collection.add_asset(asset_key, Asset(asset_dict)) + asset_dict = dict(asset_dict) + asset_dict.setdefault("media_type", asset_dict.pop("type", None)) + collection.add_asset(asset_key, Asset(**asset_dict)) return collection diff --git a/tests/data-files/collections/multi-extent.json b/tests/data-files/collections/multi-extent.json index 754c3095c..e6f4bdfa1 100644 --- a/tests/data-files/collections/multi-extent.json +++ b/tests/data-files/collections/multi-extent.json @@ -56,5 +56,13 @@ ] } }, - "license": "proprietary" + "license": "proprietary", + "assets": { + "asset": { + "href": "/path/to/asset.json", + "title": "asset title", + "description": "asset description", + "type": "application/json" + } + } } \ No newline at end of file diff --git a/tests/test_collection.py b/tests/test_collection.py index cb341f7a0..ddac7d2ea 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -175,6 +175,19 @@ def test_collection_with_href_caches_by_href(self) -> None: # cached only by HREF self.assertEqual(len(cache.id_keys_to_objects), 0) + def test_assets(self) -> None: + collection = pystac.Collection.from_file( + TestCases.get_path("data-files/collections/multi-extent.json"), + ) + result = collection.assets["asset"] + expected = pystac.Asset( + href="/path/to/asset.json", + title="asset title", + description="asset description", + media_type="application/json", + ) + self.assertEqual(result.to_dict(), expected.to_dict()) + class ExtentTest(unittest.TestCase): def test_spatial_allows_single_bbox(self) -> None: