Skip to content

Commit

Permalink
Timeout, readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
ways committed Nov 25, 2024
1 parent 85a83ca commit 92325fc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sedr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def parse_locations(jsondata) -> None:
# )


def test_conformance_links(jsondata) -> tuple[bool, str]:
def test_conformance_links(jsondata: dict, timeout: int) -> tuple[bool, str]:
"""Test that all conformance links are valid and resolves."""
msg = ""
for link in jsondata["conformsTo"]:
Expand All @@ -143,21 +143,21 @@ def test_conformance_links(jsondata) -> tuple[bool, str]:
# TODO: These links are part of the standard but doesn't work, so skipping for now.
msg += f"test_conformance_links Link {link} doesn't resolv, but that is a known issue. "
continue
resp = None
response = requests.Response()
try:
resp = requests.head(url=link, timeout=10)
response = requests.head(url=link, timeout=timeout)
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 not response.status_code < 400:
msg += f"test_conformance_links Link {link} from /conformance is broken (gives status code {response.status_code}). "
if msg:
return False, msg
return True, ""


def locate_openapi_url(url: str) -> str:
def locate_openapi_url(url: str, timeout: int) -> str:
"""Locate the OpenAPI URL based on main URL."""
request = requests.get(url, timeout=10)
request = requests.get(url, timeout=timeout)

# Json
# See https://github.com/metno/sedr/issues/6
Expand Down

0 comments on commit 92325fc

Please sign in to comment.