Skip to content

Commit

Permalink
Lint and enable test_conformance_links
Browse files Browse the repository at this point in the history
  • Loading branch information
ways committed Nov 25, 2024
1 parent ab5fab1 commit 0908211
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion sedr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Lars Falk-Petersen"
__license__ = "GPL-3.0"
__version__ = "v0.7.5"
__version__ = "v0.8.0"

import sys
import pytest
Expand Down
30 changes: 24 additions & 6 deletions sedr/edreq11.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,35 @@ def requirement9_1(jsondata) -> tuple[bool, str]:
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. See <{spec_ref}> for more info."
return (
False,
"Landing page does not contain a title. See <{spec_ref}> for more info.",
)
if "description" not in jsondata:
return False, "Landing page does not contain a description. See <{spec_ref}> for more info."
return (
False,
"Landing page does not contain a description. See <{spec_ref}> for more info.",
)
if "links" not in jsondata:
return False, "Landing page does not contain links. See <{spec_ref}> for more info."
return (
False,
"Landing page does not contain links. See <{spec_ref}> for more info.",
)
for link in jsondata["links"]:
if not isinstance(link, dict):
return False, f"Link {link} is not a dictionary. See <{spec_ref}> for more info."
return (
False,
f"Link {link} is not a dictionary. See <{spec_ref}> for more info.",
)
if "href" not in link:
return False, f"Link {link} does not have a href attribute. See <{spec_ref}> for more info."
return (
False,
f"Link {link} does not have a href attribute. See <{spec_ref}> for more info.",
)
if "rel" not in link:
return False, f"Link {link} does not have a rel attribute. See <{spec_ref}> for more info."
return (
False,
f"Link {link} does not have a rel attribute. See <{spec_ref}> for more info.",
)
util.logger.debug("requirement9_1 Landing page contains required elements.")
return True, ""
17 changes: 10 additions & 7 deletions sedr/preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import util
import requests
import json
from urllib.parse import urljoin
import edreq11 as edreq
import rodeoprofile10 as rodeoprofile


def test_site_response(url: str, timeout=10) -> bool:
"""Check basic response."""
"""Check basic http response."""
response = requests.get(url, timeout=timeout)
if not response.status_code < 400:
util.logger.error(
"Landing page doesn't respond correctly: status code: %s", response.status_code
"Landing page doesn't respond correctly: status code: %s",
response.status_code,
)
return False
return True
Expand Down Expand Up @@ -41,11 +43,6 @@ def parse_landing(url, timeout=10) -> bool:
util.logger.error(requirementA2_2_A7_message)
return False

resolves, resolves_message = util.test_conformance_links(jsondata=landing_json)
if not resolves:
util.logger.error(resolves_message)
return False

return True, landing_json


Expand All @@ -60,6 +57,12 @@ def parse_conformance(url: str, timeout: int, landing_json) -> bool:
util.logger.warning("Conformance page <%s> is not valid JSON.", url)
return False

resolves, resolves_message = util.test_conformance_links(jsondata=conformance_json)
util.logger.error(resolves_message)
# TODO: reenable when all conformance links resolves
# if not resolves and util.args.strict:
# return False

requirementA2_2_A5, requirementA2_2_A5_message = edreq.requirementA2_2_A5(
jsondata=conformance_json, siteurl=util.args.url
)
Expand Down
25 changes: 12 additions & 13 deletions sedr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,19 @@ def parse_locations(jsondata) -> None:
def test_conformance_links(jsondata) -> tuple[bool, str]: # pylint: disable=unused-argument
"""Test that all conformance links are valid and resolves.
TODO: http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections doesn't work, so postponing this.
TODO: http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections doesn't work, so not erroring out.
"""
# for link in conformance_json["conformsTo"]:
# resp = None
# try:
# resp = requests.head(url=link, timeout=10)
# except requests.exceptions.MissingSchema as error:
# raise AssertionError(
# f"Link <{link}> from /conformance is malformed: {error})."
# ) from error
# assert (
# resp.status_code < 400
# ), f"Link {link} from /conformance is broken (gives status code {resp.status_code})."
logger.debug("test_conformance_links is NOOP")
msg = ""
for link in jsondata["conformsTo"]:
resp = None
try:
resp = requests.head(url=link, timeout=10)
except requests.exceptions.MissingSchema as error:
msg += f"test_conformance_links Link <{link}> from /conformance is malformed: {error}). "
if not resp.status_code < 400:
msg += f"test_conformance_links Link {link} from /conformance is broken (gives status code {resp.status_code}). "
if msg:
return False, msg
return True, ""


Expand Down

0 comments on commit 0908211

Please sign in to comment.