Skip to content

Commit 0908211

Browse files
committed
Lint and enable test_conformance_links
1 parent ab5fab1 commit 0908211

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

sedr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
__author__ = "Lars Falk-Petersen"
44
__license__ = "GPL-3.0"
5-
__version__ = "v0.7.5"
5+
__version__ = "v0.8.0"
66

77
import sys
88
import pytest

sedr/edreq11.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,35 @@ def requirement9_1(jsondata) -> tuple[bool, str]:
101101
spec_ref = "https://docs.ogc.org/is/19-072/19-072.html#_7c772474-7037-41c9-88ca-5c7e95235389"
102102

103103
if "title" not in jsondata:
104-
return False, "Landing page does not contain a title. See <{spec_ref}> for more info."
104+
return (
105+
False,
106+
"Landing page does not contain a title. See <{spec_ref}> for more info.",
107+
)
105108
if "description" not in jsondata:
106-
return False, "Landing page does not contain a description. See <{spec_ref}> for more info."
109+
return (
110+
False,
111+
"Landing page does not contain a description. See <{spec_ref}> for more info.",
112+
)
107113
if "links" not in jsondata:
108-
return False, "Landing page does not contain links. See <{spec_ref}> for more info."
114+
return (
115+
False,
116+
"Landing page does not contain links. See <{spec_ref}> for more info.",
117+
)
109118
for link in jsondata["links"]:
110119
if not isinstance(link, dict):
111-
return False, f"Link {link} is not a dictionary. See <{spec_ref}> for more info."
120+
return (
121+
False,
122+
f"Link {link} is not a dictionary. See <{spec_ref}> for more info.",
123+
)
112124
if "href" not in link:
113-
return False, f"Link {link} does not have a href attribute. See <{spec_ref}> for more info."
125+
return (
126+
False,
127+
f"Link {link} does not have a href attribute. See <{spec_ref}> for more info.",
128+
)
114129
if "rel" not in link:
115-
return False, f"Link {link} does not have a rel attribute. See <{spec_ref}> for more info."
130+
return (
131+
False,
132+
f"Link {link} does not have a rel attribute. See <{spec_ref}> for more info.",
133+
)
116134
util.logger.debug("requirement9_1 Landing page contains required elements.")
117135
return True, ""

sedr/preflight.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
import util
44
import requests
5+
import json
56
from urllib.parse import urljoin
67
import edreq11 as edreq
78
import rodeoprofile10 as rodeoprofile
89

910

1011
def test_site_response(url: str, timeout=10) -> bool:
11-
"""Check basic response."""
12+
"""Check basic http response."""
1213
response = requests.get(url, timeout=timeout)
1314
if not response.status_code < 400:
1415
util.logger.error(
15-
"Landing page doesn't respond correctly: status code: %s", response.status_code
16+
"Landing page doesn't respond correctly: status code: %s",
17+
response.status_code,
1618
)
1719
return False
1820
return True
@@ -41,11 +43,6 @@ def parse_landing(url, timeout=10) -> bool:
4143
util.logger.error(requirementA2_2_A7_message)
4244
return False
4345

44-
resolves, resolves_message = util.test_conformance_links(jsondata=landing_json)
45-
if not resolves:
46-
util.logger.error(resolves_message)
47-
return False
48-
4946
return True, landing_json
5047

5148

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

60+
resolves, resolves_message = util.test_conformance_links(jsondata=conformance_json)
61+
util.logger.error(resolves_message)
62+
# TODO: reenable when all conformance links resolves
63+
# if not resolves and util.args.strict:
64+
# return False
65+
6366
requirementA2_2_A5, requirementA2_2_A5_message = edreq.requirementA2_2_A5(
6467
jsondata=conformance_json, siteurl=util.args.url
6568
)

sedr/util.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,19 @@ def parse_locations(jsondata) -> None:
134134
def test_conformance_links(jsondata) -> tuple[bool, str]: # pylint: disable=unused-argument
135135
"""Test that all conformance links are valid and resolves.
136136
137-
TODO: http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections doesn't work, so postponing this.
137+
TODO: http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections doesn't work, so not erroring out.
138138
"""
139-
# for link in conformance_json["conformsTo"]:
140-
# resp = None
141-
# try:
142-
# resp = requests.head(url=link, timeout=10)
143-
# except requests.exceptions.MissingSchema as error:
144-
# raise AssertionError(
145-
# f"Link <{link}> from /conformance is malformed: {error})."
146-
# ) from error
147-
# assert (
148-
# resp.status_code < 400
149-
# ), f"Link {link} from /conformance is broken (gives status code {resp.status_code})."
150-
logger.debug("test_conformance_links is NOOP")
139+
msg = ""
140+
for link in jsondata["conformsTo"]:
141+
resp = None
142+
try:
143+
resp = requests.head(url=link, timeout=10)
144+
except requests.exceptions.MissingSchema as error:
145+
msg += f"test_conformance_links Link <{link}> from /conformance is malformed: {error}). "
146+
if not resp.status_code < 400:
147+
msg += f"test_conformance_links Link {link} from /conformance is broken (gives status code {resp.status_code}). "
148+
if msg:
149+
return False, msg
151150
return True, ""
152151

153152

0 commit comments

Comments
 (0)