Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### Fixed

- `Collection.from_dict` and `Collection.from_file` now correctly construct `Asset` objects.

### Removed

## [1.0.0-beta.2]
Expand Down
4 changes: 3 additions & 1 deletion pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll assume it's deliberate that we use media_type here instead of type. Anything else I should watch out for?

collection.add_asset(asset_key, Asset(**asset_dict))

return collection

Expand Down
10 changes: 9 additions & 1 deletion tests/data-files/collections/multi-extent.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,13 @@
]
}
},
"license": "proprietary"
"license": "proprietary",
"assets": {
"asset": {
"href": "/path/to/asset.json",
"title": "asset title",
"description": "asset description",
"type": "application/json"
}
}
}
13 changes: 13 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down