From 4a1272b8cb37773415362190852204669b0e18d8 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Fri, 21 Jan 2022 16:13:44 -0500 Subject: [PATCH 1/3] Add failing test --- tests/test_catalog.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 4b4425897..c4c8d0715 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -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() From 56f9d158745571b6604f04855d526a677681f8c6 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Fri, 21 Jan 2022 16:12:29 -0500 Subject: [PATCH 2/3] No self links in relative published Items --- pystac/catalog.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pystac/catalog.py b/pystac/catalog.py index ca466a0e9..dedea2fe7 100644 --- a/pystac/catalog.py +++ b/pystac/catalog.py @@ -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) From fc392f33d14b132d424940321d5b62a048a25e14 Mon Sep 17 00:00:00 2001 From: Jon Duckworth Date: Fri, 21 Jan 2022 16:17:38 -0500 Subject: [PATCH 3/3] Add CHANGELOG entry for #725 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 681684073..d05ce5dff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]