Skip to content

Commit

Permalink
Merge pull request #24 from metno/21-implement-rodeo-profile-73-colle…
Browse files Browse the repository at this point in the history
…ction-identifier

21 implement rodeo profile 73 collection identifier
  • Loading branch information
ways authored Nov 22, 2024
2 parents f89f39e + 714fb51 commit e5e25d2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ logs
.tox
old
.*_cache
.ropeproject
36 changes: 36 additions & 0 deletions sedr/rodeoprofile10.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ def requirement7_2(jsondata: str) -> tuple[bool, str]:
return True, ""


def requirement7_3(jsondata) -> tuple[bool, str]:
"""Check collection identifier. Can only test B, C.
This should only be tested if --strict is set."""
spec_url = f"{spec_base_url}#_collection_identifier"
approved_data_types = [
"insitu-observations",
"climate_data",
"radar_observations",
"weather_warnings",
"weather_forecast",
]

# B
try:
for t in approved_data_types:
if jsondata["id"].startswith(t):
break
else:
return (
False,
f"Collection id SHOULD be from the following list of values: "
f"{', '.join(approved_data_types)}. A postfix can be added. "
f"Found: <{jsondata['id']}>. See <{spec_url}> for more info.",
)
except (json.JSONDecodeError, KeyError) as err:
return (
False,
f"Collection must have an id. None found in collection <{jsondata}>."
f"Error {err}.",
)
return (
True,
"",
)


def requirement7_4(jsondata: str) -> tuple[bool, str]:
"""Check collection title. Can only test A, B."""
spec_url = f"{spec_base_url}#_collection_title"
Expand Down
14 changes: 10 additions & 4 deletions sedr/schemat.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_openapi(case):
except schemathesis.exceptions.CheckFailed as err:
# raise AssertionError(
causes = None
if err is not None and len(err.causes) > 0:
if err is not None and err.causes is not None:
causes = ", ".join(err.causes[0].args)
else:
pass
Expand Down Expand Up @@ -156,6 +156,7 @@ def test_edr_conformance(case):
def test_edr_landingpage(case):
"""Test that the landing page contains required elements."""
spec_ref = "https://docs.ogc.org/is/19-072/19-072.html#_7c772474-7037-41c9-88ca-5c7e95235389"
landingpage_json = None
response = case.call()
try:
landingpage_json = json.loads(response.text)
Expand All @@ -167,9 +168,8 @@ def test_edr_landingpage(case):

util.logger.debug("Landingpage %s tested OK", response.url)
except json.decoder.JSONDecodeError:
util.logger.warning(
"Landing page is not valid JSON, other formats are not tested yet."
)
util.logger.warning("Landing page is not valid JSON.")
raise AssertionError("Landing page is not valid JSON")

if use_rodeoprofile:
requirement7_2, requirement7_2_message = rodeoprofile.requirement7_2(
Expand Down Expand Up @@ -230,6 +230,12 @@ def test_edr_collections(case):
) from err

if use_rodeoprofile:
requirement7_3, requirement7_3_message = rodeoprofile.requirement7_3(
jsondata=collection
)
if not requirement7_3:
raise AssertionError(requirement7_3_message)

requirement7_4, requirement7_4_message = rodeoprofile.requirement7_4(
jsondata=collection
)
Expand Down

0 comments on commit e5e25d2

Please sign in to comment.