Skip to content

Commit

Permalink
Linting and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ways committed Nov 25, 2024
1 parent e9345f6 commit ab5fab1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
18 changes: 12 additions & 6 deletions sedr/edreq11.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def requirementA2_2_A5(jsondata: str, siteurl="") -> tuple[bool, str]:
f"Conformance page <{siteurl}conformance> does not contain the core edr class {url}. See <{spec_url}> for more info.",
)

util.logger.debug(
"requirementA2_2_A5: conformance page contains the required EDR classes."
)
return True, ""


Expand All @@ -49,6 +52,7 @@ def requirementA2_2_A7(version: int) -> tuple[bool, str]:
"""
spec_url = "https://docs.ogc.org/is/19-086r6/19-086r6.html#_0d0c25a0-850f-2aa5-9acb-06efcc04d452"
if version == 11:
util.logger.debug("requirementA2_2_A7 HTTP version 1.1 was used.")
return True, ""

return False, f"HTTP version 1.1 was not used. See <{spec_url}> for more info."
Expand All @@ -71,6 +75,7 @@ def requirementA11_1(jsondata: str) -> tuple[bool, str]:
or util.args.openapi_version == "3.0"
and "oas30" in url
):
util.logger.debug("requirementA11_1 Found openapi class <%s>", url)
return True, url
return (
False,
Expand All @@ -96,16 +101,17 @@ 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."
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."
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."
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."
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."
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."
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, ""
21 changes: 11 additions & 10 deletions sedr/preflight.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Run a series of simple preflight checks before invoking schemathesis. """
"""Run a series of simple preflight checks before invoking schemathesis."""

import sys
import util
import requests
from urllib.parse import urljoin
Expand All @@ -10,9 +9,11 @@

def test_site_response(url: str, timeout=10) -> bool:
"""Check basic response."""
response = requests.get(util.args.url, timeout=timeout)
response = requests.get(url, timeout=timeout)
if not response.status_code < 400:
util.logger.error(f"Landing page doesn't respond correctly: status code: {response.status_code}")
util.logger.error(
"Landing page doesn't respond correctly: status code: %s", response.status_code
)
return False
return True

Expand Down Expand Up @@ -40,17 +41,15 @@ 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
)
resolves, resolves_message = util.test_conformance_links(jsondata=landing_json)
if not resolves:
util.logger.error(resolves_message)
return False

return True, landing_json


def parse_conformance(url: str, timeout=10, landing_json={}) -> bool:
def parse_conformance(url: str, timeout: int, landing_json) -> bool:
"""Test that the conformance page contains required elements."""
conformance_json = None
response = requests.get(url, timeout=timeout)
Expand All @@ -77,7 +76,10 @@ def parse_conformance(url: str, timeout=10, landing_json={}) -> bool:

# Rodeo profile

if util.args.rodeo_profile or rodeoprofile.conformance_url in conformance_json["conformsTo"]:
if (
util.args.rodeo_profile
or rodeoprofile.conformance_url in conformance_json["conformsTo"]
):
util.logger.info(
"Including tests for Rodeo profile %s", rodeoprofile.conformance_url
)
Expand All @@ -89,7 +91,6 @@ def parse_conformance(url: str, timeout=10, landing_json={}) -> bool:
util.logger.error(requirement7_2_message)
return False


requirement7_1, requirement7_1_message = rodeoprofile.requirement7_1(
jsondata=conformance_json
)
Expand Down
12 changes: 8 additions & 4 deletions sedr/rodeoprofile10.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""rodeo-edr-profile requirements. See <http://rodeo-project.eu/rodeo-edr-profile>."""

import json
import util

conformance_url = "http://rodeo-project.eu/spec/rodeo-edr-profile/1/req/core"
spec_base_url = (
Expand All @@ -9,15 +10,14 @@


def requirement7_1(jsondata: str) -> tuple[bool, str]:
"""Check if the conformance page contains the required EDR classes.
"""
"""Check if the conformance page contains the required EDR classes."""
spec_url = f"{spec_base_url}#_requirements_class_core"
if conformance_url not in jsondata["conformsTo"]:
return (
False,
f"Conformance page /conformance does not contain the profile class {conformance_url}. See <{spec_url}> for more info.",
)

util.logger.debug("Rodeoprofile Requirement 7.1 OK")
return True, ""


Expand Down Expand Up @@ -60,6 +60,7 @@ def requirement7_2(jsondata: str) -> tuple[bool, str]:
False,
f"Landing page should linkt to service-doc, with type {servicedoc_type}. See <{spec_url}> for more info.",
)
util.logger.debug("Rodeoprofile Requirement 7.2 OK")
return True, ""


Expand Down Expand Up @@ -93,6 +94,7 @@ def requirement7_3(jsondata) -> tuple[bool, str]:
f"Collection must have an id. None found in collection <{jsondata}>."
f"Error {err}.",
)
util.logger.debug("Rodeoprofile Requirement 7.3 OK")
return (
True,
"",
Expand All @@ -110,12 +112,13 @@ def requirement7_4(jsondata: str) -> tuple[bool, str]:
False,
f"Collection title should not exceed 50 chars. See <{spec_url}> for more info.",
)
except (json.JSONDecodeError, KeyError) as err:
except (json.JSONDecodeError, KeyError):
# A
return (
False,
f"Collection must have a title, but it seems to be missing. See <{spec_url}> and {spec_base_url}#_collection_title_2 for more info.",
)
util.logger.debug("Rodeoprofile Requirement 7.4 OK")
return (
True,
"",
Expand All @@ -139,6 +142,7 @@ def requirement7_5(jsondata: str) -> tuple[bool, str]:
False,
f"Collection <{jsondata['id']}> is missing a license link with rel='license'. See <{spec_url}> A, B for more info.",
)
util.logger.debug("Rodeoprofile Requirement 7.5 OK")
return (
True,
"",
Expand Down
1 change: 0 additions & 1 deletion sedr/test_schemat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import unittest
import util
import pytest


class TestInit(unittest.TestCase):
Expand Down
14 changes: 0 additions & 14 deletions sedr/test_util.py

This file was deleted.

4 changes: 2 additions & 2 deletions sedr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
from urllib.parse import urlsplit


__author__ = "Lars Falk-Petersen"
__license__ = "GPL-3.0"

Expand Down Expand Up @@ -70,7 +69,7 @@ def parse_args(args, version: str = "") -> argparse.Namespace:

def set_up_logging(args, logfile=None, version: str = "") -> logging.Logger:
"""Set up logging."""
loglevel = logging.WARNING
loglevel = logging.DEBUG

logger = logging.getLogger(__file__)
logger.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -148,6 +147,7 @@ def test_conformance_links(jsondata) -> tuple[bool, str]: # pylint: disable=unu
# 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")
return True, ""


Expand Down

0 comments on commit ab5fab1

Please sign in to comment.