Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix root link bug #100

Merged
merged 2 commits into from
Jun 9, 2020
Merged
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
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)