From e09f1d747a1276215110d27ae46e496fdb04a933 Mon Sep 17 00:00:00 2001 From: Gabriel Ratcliff Date: Tue, 19 Sep 2023 10:23:59 -0700 Subject: [PATCH] chore: lint fix --- packages/python/readme_metrics/GetProjectBaseUrl.py | 8 +++++--- packages/python/readme_metrics/Metrics.py | 4 ++-- packages/python/readme_metrics/PayloadBuilder.py | 4 +++- .../python/readme_metrics/tests/GetProjectBaseUrl_test.py | 6 ++++-- packages/python/readme_metrics/tests/Metrics_test.py | 2 ++ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/python/readme_metrics/GetProjectBaseUrl.py b/packages/python/readme_metrics/GetProjectBaseUrl.py index 9f1370e8ee..f17f87ee03 100644 --- a/packages/python/readme_metrics/GetProjectBaseUrl.py +++ b/packages/python/readme_metrics/GetProjectBaseUrl.py @@ -6,6 +6,7 @@ import base64 import requests + def auth(readme_api_key: str) -> Dict[str, str]: encodedAuth = base64.b64encode(f"{readme_api_key}:".encode("utf8")).decode("utf8") return {"Authorization": f"Basic {encodedAuth}"} @@ -13,14 +14,15 @@ def auth(readme_api_key: str) -> Dict[str, str]: @lru_cache(maxsize=None) def get_project_base_url( - readme_api_url: str, readme_api_key: str, - timeout: int, logger: Logger + readme_api_url: str, readme_api_key: str, timeout: int, logger: Logger ) -> str: """returns the baseUrl for the current API key""" try: response = requests.get( - urljoin(readme_api_url, "/v1"), headers=auth(readme_api_key), timeout=timeout + urljoin(readme_api_url, "/v1"), + headers=auth(readme_api_key), + timeout=timeout, ) response.raise_for_status() return response.json()["baseUrl"] diff --git a/packages/python/readme_metrics/Metrics.py b/packages/python/readme_metrics/Metrics.py index ce1cf0b6a9..adb9d1a86a 100644 --- a/packages/python/readme_metrics/Metrics.py +++ b/packages/python/readme_metrics/Metrics.py @@ -72,10 +72,10 @@ def process(self, request, response: ResponseInfoWrapper) -> None: self.config.README_API_URL, self.config.README_API_KEY, self.config.METRICS_API_TIMEOUT, - self.config.LOGGER + self.config.LOGGER, ) # Construct header link from base_url and logId - response.headers['x-documentation-url'] = f"{base_url}/logs/{logId}" + response.headers["x-documentation-url"] = f"{base_url}/logs/{logId}" payload = self.payload_builder(request, response, logId) if payload is None: diff --git a/packages/python/readme_metrics/PayloadBuilder.py b/packages/python/readme_metrics/PayloadBuilder.py index 6274efb7f7..c2c4b14b3e 100644 --- a/packages/python/readme_metrics/PayloadBuilder.py +++ b/packages/python/readme_metrics/PayloadBuilder.py @@ -57,7 +57,9 @@ def __init__( self.grouping_function = grouping_function self.logger = logger - def __call__(self, request, response: ResponseInfoWrapper, logId: str) -> Optional[dict]: + def __call__( + self, request, response: ResponseInfoWrapper, logId: str + ) -> Optional[dict]: """Builds a HAR payload encompassing the request & response data Args: diff --git a/packages/python/readme_metrics/tests/GetProjectBaseUrl_test.py b/packages/python/readme_metrics/tests/GetProjectBaseUrl_test.py index fef9fd1ba5..8bdc47b680 100644 --- a/packages/python/readme_metrics/tests/GetProjectBaseUrl_test.py +++ b/packages/python/readme_metrics/tests/GetProjectBaseUrl_test.py @@ -51,11 +51,13 @@ def fixture_readme_api_v1_http_error(monkeypatch): ) -def test_get_project_base_url(readme_api_v1_success): # pylint: disable=unused-argument +def test_get_project_base_url(readme_api_v1_success): # pylint: disable=unused-argument assert get_project_base_url("", "secretkey", 3, FakeLogger) == "https://zombo.com" -def test_get_project_base_url_exception(readme_api_v1_http_error): # pylint: disable=unused-argument +def test_get_project_base_url_exception( + readme_api_v1_http_error, +): # pylint: disable=unused-argument try: get_project_base_url("", "secretkey", 3, FakeLogger) assert False diff --git a/packages/python/readme_metrics/tests/Metrics_test.py b/packages/python/readme_metrics/tests/Metrics_test.py index 02179e9199..e3c61eb3df 100644 --- a/packages/python/readme_metrics/tests/Metrics_test.py +++ b/packages/python/readme_metrics/tests/Metrics_test.py @@ -9,6 +9,7 @@ from readme_metrics.ResponseInfoWrapper import ResponseInfoWrapper from .fixtures import Environ + def mock_request(): body = json.dumps({"ok": 123, "password": 456}).encode() environ = Environ.MockEnviron().getEnvironForRequest(body, "POST") @@ -18,6 +19,7 @@ def mock_request(): req.rm_body = body return req + class TestMetrics: def test_grouping_function_import(self): config = MetricsApiConfig(api_key=123456, grouping_function="json.loads")