Skip to content

Commit

Permalink
Move checks from schemathesis to preflight.
Browse files Browse the repository at this point in the history
  • Loading branch information
ways committed Nov 22, 2024
1 parent 192d809 commit e18a36d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
21 changes: 21 additions & 0 deletions sedr/edreq11.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,24 @@ def requirementA11_1(jsondata: str) -> tuple[bool, str]:
False,
f"Conformance page /conformance does not contain an openapi class. See <{spec_url}> for more info.",
)


def requirement9_1(jsondata) -> tuple[bool, str]:
"""Test that the landing page contains required elements.
TODO: See https://github.com/metno/sedr/issues/6 """
spec_ref = "https://docs.ogc.org/is/19-072/19-072.html#_7c772474-7037-41c9-88ca-5c7e95235389"

if "title" not in jsondata:
return False, "Landing page does not contain a title."
if "description" not in jsondata:
return False, "Landing page does not contain a description."
if "links" not in jsondata:
return False, "Landing page does not contain links."
for link in jsondata["links"]:
if not isinstance(link, dict):
return False, f"Link {link} is not a dictionary."
if "href" not in link:
return False, f"Link {link} does not have a href attribute."
if "rel" not in link:
return False, f"Link {link} does not have a rel attribute."
return True, ""
28 changes: 0 additions & 28 deletions sedr/schemat.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,34 +151,6 @@ def test_edr_conformance(case):
util.logger.debug("Conformance %s tested OK", response.url)


@schema.include(path_regex="^" + util.args.base_path + "$").parametrize()
@settings(max_examples=util.args.iterations, deadline=None)
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)
landing, landing_message = util.parse_landing_json(landingpage_json)
if not landing:
raise AssertionError(
f"Landing page is missing required elements. See <{spec_ref}> for more info. {landing_message}"
)

util.logger.debug("Landingpage %s tested OK", response.url)
except json.decoder.JSONDecodeError:
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(
jsondata=landingpage_json
)
if not requirement7_2:
raise AssertionError(requirement7_2_message)


@schema.include(
path_regex="^" + os.path.join(util.args.base_path, "collections$")
).parametrize()
Expand Down

0 comments on commit e18a36d

Please sign in to comment.