From ab5fab198e717451bf39414fc498ffddb99b7550 Mon Sep 17 00:00:00 2001 From: Lars Falk-Petersen Date: Mon, 25 Nov 2024 10:39:59 +0100 Subject: [PATCH] Linting and bugfix --- sedr/edreq11.py | 18 ++++++++++++------ sedr/preflight.py | 21 +++++++++++---------- sedr/rodeoprofile10.py | 12 ++++++++---- sedr/test_schemat.py | 1 - sedr/test_util.py | 14 -------------- sedr/util.py | 4 ++-- 6 files changed, 33 insertions(+), 37 deletions(-) delete mode 100644 sedr/test_util.py diff --git a/sedr/edreq11.py b/sedr/edreq11.py index 72b225d..36e98ee 100644 --- a/sedr/edreq11.py +++ b/sedr/edreq11.py @@ -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, "" @@ -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." @@ -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, @@ -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, "" diff --git a/sedr/preflight.py b/sedr/preflight.py index 00eb161..a11a29e 100644 --- a/sedr/preflight.py +++ b/sedr/preflight.py @@ -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 @@ -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 @@ -40,9 +41,7 @@ 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 @@ -50,7 +49,7 @@ def parse_landing(url, timeout=10) -> bool: 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) @@ -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 ) @@ -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 ) diff --git a/sedr/rodeoprofile10.py b/sedr/rodeoprofile10.py index 51394c3..c195060 100644 --- a/sedr/rodeoprofile10.py +++ b/sedr/rodeoprofile10.py @@ -1,6 +1,7 @@ """rodeo-edr-profile requirements. See .""" import json +import util conformance_url = "http://rodeo-project.eu/spec/rodeo-edr-profile/1/req/core" spec_base_url = ( @@ -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, "" @@ -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, "" @@ -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, "", @@ -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, "", @@ -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, "", diff --git a/sedr/test_schemat.py b/sedr/test_schemat.py index c0b371c..ee83b38 100644 --- a/sedr/test_schemat.py +++ b/sedr/test_schemat.py @@ -2,7 +2,6 @@ import unittest import util -import pytest class TestInit(unittest.TestCase): diff --git a/sedr/test_util.py b/sedr/test_util.py deleted file mode 100644 index 412935f..0000000 --- a/sedr/test_util.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Unit tests for util.py.""" - -import unittest -import json -import util - - -class TestUtil(unittest.TestCase): - def test_parse_landing_json(self): - """Test parsing a generic landing page in json.""" - with open("testdata/landingpage.json", "r", encoding="utf-8") as f: - landingpage_json = json.loads(f.read()) - landing, _ = util.parse_landing_json(landingpage_json) - self.assertTrue(landing) diff --git a/sedr/util.py b/sedr/util.py index dffd275..96667fb 100644 --- a/sedr/util.py +++ b/sedr/util.py @@ -6,7 +6,6 @@ import json from urllib.parse import urlsplit - __author__ = "Lars Falk-Petersen" __license__ = "GPL-3.0" @@ -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) @@ -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, ""