Skip to content

Commit

Permalink
Merge pull request #100 from azavea/sjk/item-root-bug-fix
Browse files Browse the repository at this point in the history
fix root link bug
  • Loading branch information
lossyrob authored Jun 9, 2020
2 parents 757f5e4 + 7d7b63f commit 813e9bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pystac/stac_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,10 @@ def from_file(cls, href):

# If this is a root catalog, set the root to the catalog instance.
root_link = o.get_root_link()
if not root_link.is_resolved():
if root_link.get_absolute_href() == href:
o.set_root(o, link_type=root_link.link_type)
if root_link is not None:
if not root_link.is_resolved():
if root_link.get_absolute_href() == href:
o.set_root(o, link_type=root_link.link_type)
return o

@classmethod
Expand Down
9 changes: 9 additions & 0 deletions tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ def test_read_eo_item_owns_asset(self):
assert len(item.assets) > 0
for asset_key in item.assets:
self.assertEqual(item.assets[asset_key].owner, item)

def test_self_contained_item(self):
m = TestCases.get_path('data-files/itemcollections/sample-item-collection.json')
with open(m) as f:
item_dict = json.load(f)['features'][0]
item_dict['links'] = [l for l in item_dict['links'] if l['rel'] == 'self']
item = Item.from_dict(item_dict)
self.assertIsInstance(item, Item)
self.assertEqual(len(item.links), 1)

0 comments on commit 813e9bb

Please sign in to comment.