Skip to content
Merged
49 changes: 49 additions & 0 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,55 @@ def check_all_absolute(cat: Catalog) -> None:
c2.catalog_type = CatalogType.ABSOLUTE_PUBLISHED
check_all_absolute(c2)

def test_self_contained_catalog_collection_item_links(self) -> None:
"""See issue https://github.com/stac-utils/pystac/issues/657"""
with tempfile.TemporaryDirectory() as tmp_dir:
catalog = pystac.Catalog(
id="catalog-issue-657", description="catalog-issue-657"
)
collection = pystac.Collection(
"collection-issue-657",
"collection-issue-657",
pystac.Extent(
spatial=pystac.SpatialExtent([[-180.0, -90.0, 180.0, 90.0]]),
temporal=pystac.TemporalExtent([[datetime(2021, 11, 1), None]]),
),
license="proprietary",
)

item = pystac.Item(
id="item-issue-657",
stac_extensions=[],
geometry=ARBITRARY_GEOM,
bbox=ARBITRARY_BBOX,
datetime=datetime(2021, 11, 1),
properties={},
)

collection.add_item(item)
catalog.add_child(collection)

catalog.normalize_hrefs(tmp_dir)
catalog.validate_all()

catalog.save(catalog_type=CatalogType.SELF_CONTAINED)
item_json = json.loads(
open(
f"{tmp_dir}/collection-issue-657/item-issue-657/item-issue-657.json"
).read()
)

for link in item_json["links"]:
# self links are always absolute
if link["rel"] == "self":
continue

href = link["href"]
self.assertFalse(
is_absolute_href(href),
msg=f"Link with rel={link['rel']} is absolute!",
)

def test_full_copy_and_normalize_works_with_created_stac(self) -> None:
cat = TestCases.test_case_3()
cat_copy = cat.full_copy()
Expand Down