Skip to content

Commit

Permalink
No self links in relative published items (#725)
Browse files Browse the repository at this point in the history
* Add failing test

* No self links in relative published Items

* Add CHANGELOG entry for #725
  • Loading branch information
Jon Duckworth authored Jan 24, 2022
1 parent fffe95e commit d659185
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Fixed

- Self links no longer included in Items for "relative published" catalogs ([#725](https://github.com/stac-utils/pystac/pull/725))

### Deprecated

## [v1.3.0]
Expand Down
5 changes: 4 additions & 1 deletion pystac/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,10 @@ def save(
item_dest_href = make_absolute_href(
rel_href, dest_href, start_is_dir=True
)
item.save_object(include_self_link=True, dest_href=item_dest_href)
item.save_object(
include_self_link=items_include_self_link,
dest_href=item_dest_href,
)
else:
item.save_object(include_self_link=items_include_self_link)

Expand Down
30 changes: 30 additions & 0 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,36 @@ def test_save_to_provided_href(self) -> None:
for link in result_cat.get_child_links():
self.assertTrue(cast(str, link.target).startswith(href))

def test_save_relative_published_no_self_links(self) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
catalog = TestCases.test_case_1()
href = "http://test.com"
folder = os.path.join(tmp_dir, "cat")
catalog.normalize_hrefs(href)
catalog.save(catalog_type=CatalogType.RELATIVE_PUBLISHED, dest_href=folder)

catalog_path = os.path.join(folder, "catalog.json")
self.assertTrue(os.path.exists(catalog_path))
result_cat = Catalog.from_file(catalog_path)

# Check that Items do not have a self link
# Since Item.from_dict automatically adds a self link, we need to look at
# the JSON files themselves.
stac_io = pystac.StacIO.default()

for current_cat, _, __ in result_cat.walk():
for item_link in current_cat.get_item_links():
item_dict = stac_io.read_json(item_link)
self_link = next(
(
link
for link in item_dict.get("links", [])
if link["rel"] == "self"
),
None,
)
self.assertIsNone(self_link)

def test_subcatalogs_saved_to_correct_path(self) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
catalog = TestCases.test_case_1()
Expand Down

0 comments on commit d659185

Please sign in to comment.