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

No self links in relative published items #725

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
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