Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
fix: Ignore optional title links in tests
Browse files Browse the repository at this point in the history
Pystac offers optional title field in link object (human-readable title to be used in rendered displays of the link). Removing normalized_href (put in place to solve #1818) causes tests to fail due to missing title.
  • Loading branch information
Jimlinz committed Aug 10, 2022
1 parent c0627fd commit 8c9cb10
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions tests/test_populate_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import timedelta
from json import load
from time import sleep
from typing import Dict, List
from uuid import uuid4

import smart_open
Expand Down Expand Up @@ -228,33 +229,28 @@ def should_update_root_catalog_with_new_version_catalog(subtests: SubTests) -> N
{
STAC_REL_KEY: STAC_REL_ROOT,
STAC_HREF_KEY: f"./{CATALOG_FILENAME}",
STAC_TITLE_KEY: ROOT_CATALOG_TITLE,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
{
STAC_REL_KEY: STAC_REL_CHILD,
STAC_HREF_KEY: f"./{dataset.title}/{catalog_filename}",
STAC_TITLE_KEY: dataset.title,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
]
expected_dataset_version_links: JsonList = [
{
STAC_REL_KEY: STAC_REL_ROOT,
STAC_HREF_KEY: f"../{CATALOG_FILENAME}",
STAC_TITLE_KEY: ROOT_CATALOG_TITLE,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
{
STAC_REL_KEY: STAC_REL_CHILD,
STAC_HREF_KEY: f"./{collection_filename}",
STAC_TITLE_KEY: dataset.title,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
{
STAC_REL_KEY: STAC_REL_PARENT,
STAC_HREF_KEY: f"../{CATALOG_FILENAME}",
STAC_TITLE_KEY: ROOT_CATALOG_TITLE,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
]
Expand All @@ -269,15 +265,23 @@ def should_update_root_catalog_with_new_version_catalog(subtests: SubTests) -> N
mode="rb",
) as updated_root_metadata_file:
catalog_json = load(updated_root_metadata_file)
assert catalog_json[STAC_LINKS_KEY] == expected_root_catalog_links
updated_catalog_json: List[Dict[str, str]] = []
for i in catalog_json[STAC_LINKS_KEY]:
i.pop("title", None)
updated_catalog_json.append(i)
assert updated_catalog_json == expected_root_catalog_links

with subtests.test(msg="dataset version links"), smart_open.open(
f"{S3_URL_PREFIX}{Resource.STORAGE_BUCKET_NAME.resource_name}"
f"/{dataset_metadata.key}",
mode="rb",
) as updated_dataset_metadata_file:
version_json = load(updated_dataset_metadata_file)
assert version_json[STAC_LINKS_KEY] == expected_dataset_version_links
updated_version_json: List[Dict[str, str]] = []
for i in version_json[STAC_LINKS_KEY]:
i.pop("title", None)
updated_version_json.append(i)
assert updated_version_json == expected_dataset_version_links


@mark.infrastructure
Expand Down Expand Up @@ -353,21 +357,18 @@ def should_update_root_catalog_with_new_version_collection(subtests: SubTests) -
{
STAC_REL_KEY: STAC_REL_ROOT,
STAC_HREF_KEY: f"./{CATALOG_FILENAME}",
STAC_TITLE_KEY: ROOT_CATALOG_TITLE,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
{
STAC_REL_KEY: STAC_REL_CHILD,
STAC_HREF_KEY: f"./{dataset.title}/{collection_filename}",
STAC_TITLE_KEY: dataset.title,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
]
expected_dataset_version_links: JsonList = [
{
STAC_REL_KEY: STAC_REL_ROOT,
STAC_HREF_KEY: f"../{CATALOG_FILENAME}",
STAC_TITLE_KEY: ROOT_CATALOG_TITLE,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
{
Expand All @@ -378,21 +379,18 @@ def should_update_root_catalog_with_new_version_collection(subtests: SubTests) -
{
STAC_REL_KEY: STAC_REL_PARENT,
STAC_HREF_KEY: f"../{CATALOG_FILENAME}",
STAC_TITLE_KEY: ROOT_CATALOG_TITLE,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
]
expected_item_links: JsonList = [
{
STAC_REL_KEY: STAC_REL_ROOT,
STAC_HREF_KEY: f"../{CATALOG_FILENAME}",
STAC_TITLE_KEY: ROOT_CATALOG_TITLE,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
{
STAC_REL_KEY: STAC_REL_PARENT,
STAC_HREF_KEY: f"./{collection_filename}",
STAC_TITLE_KEY: dataset.title,
STAC_TYPE_KEY: STAC_MEDIA_TYPE_JSON,
},
]
Expand All @@ -407,15 +405,23 @@ def should_update_root_catalog_with_new_version_collection(subtests: SubTests) -
mode="rb",
) as updated_root_metadata_file:
catalog_json = load(updated_root_metadata_file)
assert catalog_json[STAC_LINKS_KEY] == expected_root_catalog_links
updated_catalog_json: List[Dict[str, str]] = []
for i in catalog_json[STAC_LINKS_KEY]:
i.pop("title", None)
updated_catalog_json.append(i)
assert updated_catalog_json == expected_root_catalog_links

with subtests.test(msg="dataset version links"), smart_open.open(
f"{S3_URL_PREFIX}{Resource.STORAGE_BUCKET_NAME.resource_name}"
f"/{dataset_metadata.key}",
mode="rb",
) as updated_dataset_metadata_file:
version_json = load(updated_dataset_metadata_file)
assert version_json[STAC_LINKS_KEY] == expected_dataset_version_links
updated_version_json: List[Dict[str, str]] = []
for i in version_json[STAC_LINKS_KEY]:
i.pop("title", None)
updated_version_json.append(i)
assert updated_version_json == expected_dataset_version_links

with subtests.test(msg="item links"), smart_open.open(
f"{S3_URL_PREFIX}{Resource.STORAGE_BUCKET_NAME.resource_name}/{item_metadata.key}",
Expand Down

0 comments on commit 8c9cb10

Please sign in to comment.