Skip to content

Commit a87c06e

Browse files
committed
Fix collection assets
Assets were being created with the href set to the entire asset dictionary.
1 parent 7e4602f commit a87c06e

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

pystac/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ def from_dict(
715715

716716
if assets is not None:
717717
for asset_key, asset_dict in assets.items():
718-
collection.add_asset(asset_key, Asset(asset_dict))
718+
collection.add_asset(asset_key, Asset.from_dict(asset_dict))
719719

720720
return collection
721721

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"type": "Collection",
3+
"id": "area-1-1",
4+
"stac_version": "1.0.0-rc.4",
5+
"description": "test collection country-1",
6+
"links": [
7+
{
8+
"rel": "root",
9+
"href": "./multi-extent.json",
10+
"type": "application/json"
11+
},
12+
{
13+
"rel": "item",
14+
"href": "./area-1-1-imagery/area-1-1-imagery.json",
15+
"type": "application/json"
16+
},
17+
{
18+
"rel": "item",
19+
"href": "./area-1-1-labels/area-1-1-labels.json",
20+
"type": "application/json"
21+
},
22+
{
23+
"rel": "parent",
24+
"href": "../catalog.json",
25+
"type": "application/json"
26+
}
27+
],
28+
"stac_extensions": [],
29+
"extent": {
30+
"spatial": {
31+
"bbox": [
32+
[
33+
-2.5048828125,
34+
3.8916575492899987,
35+
-1.9610595703125,
36+
4.275202171119132
37+
]
38+
]
39+
},
40+
"temporal": {
41+
"interval": [
42+
[
43+
"2019-10-04T18:55:37Z",
44+
null
45+
]
46+
]
47+
}
48+
},
49+
"license": "proprietary",
50+
"assets": {
51+
"thumbnail": {
52+
"title": "thumbnail",
53+
"href": "http://example.com/thumbnail.png",
54+
"media_type": "image/png"
55+
}
56+
}
57+
}

tests/test_collection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ def test_collection_with_href_caches_by_href(self) -> None:
175175
# cached only by HREF
176176
self.assertEqual(len(cache.id_keys_to_objects), 0)
177177

178+
def test_assets(self) -> None:
179+
path = TestCases.get_path("data-files/collections/with-assets.json")
180+
with open(path) as f:
181+
data = json.load(f)
182+
collection = pystac.read_dict(data)
183+
collection.validate()
184+
178185

179186
class ExtentTest(unittest.TestCase):
180187
def test_spatial_allows_single_bbox(self) -> None:

0 commit comments

Comments
 (0)