Skip to content

Commit

Permalink
chore: lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gratcliff committed Sep 19, 2023
1 parent 29aab56 commit e09f1d7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
8 changes: 5 additions & 3 deletions packages/python/readme_metrics/GetProjectBaseUrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
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}"}


@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"]
Expand Down
4 changes: 2 additions & 2 deletions packages/python/readme_metrics/Metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion packages/python/readme_metrics/PayloadBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/python/readme_metrics/tests/Metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit e09f1d7

Please sign in to comment.