diff --git a/.gitignore b/.gitignore index 096a268..5374aed 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ logs .tox old .*_cache +.ropeproject diff --git a/sedr/rodeoprofile10.py b/sedr/rodeoprofile10.py index ce9f5b3..02dabac 100644 --- a/sedr/rodeoprofile10.py +++ b/sedr/rodeoprofile10.py @@ -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" diff --git a/sedr/schemat.py b/sedr/schemat.py index b65c82f..14c8756 100644 --- a/sedr/schemat.py +++ b/sedr/schemat.py @@ -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 @@ -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) @@ -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( @@ -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 )