Skip to content

Commit

Permalink
Fix mypy and suppress type checks for mocked test
Browse files Browse the repository at this point in the history
  • Loading branch information
john-dupuy committed Apr 17, 2023
1 parent cfc4731 commit 773a0e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
15 changes: 9 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/stac_api_validator/validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def is_geojson_type(maybe_type: Optional[str]) -> bool:
def get_catalog(data_dict: Dict[str, Any], r_session: Session) -> Catalog:
stac_io = StacIO.default()
if r_session.headers and r_session.headers.get("Authorization"):
stac_io.headers = {"Authorization": r_session.headers["Authorization"]}
stac_io.headers = {"Authorization": str(r_session.headers["Authorization"])}
catalog = Catalog.from_dict(data_dict)
catalog._stac_io = stac_io
return catalog
Expand Down Expand Up @@ -598,7 +598,7 @@ def validate_api(
try:
headers = {}
if r_session.headers and r_session.headers.get("Authorization"):
headers["Authorization"] = r_session.headers["Authorization"]
headers["Authorization"] = str(r_session.headers["Authorization"])
catalog = Client.open(root_url, headers=headers)
catalog.validate()
for child in catalog.get_children():
Expand Down
41 changes: 22 additions & 19 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
from click.testing import CliRunner
from typeguard import suppress_type_checks

from stac_api_validator import __main__

Expand All @@ -20,22 +21,24 @@ def test_main_fails(runner: CliRunner) -> None:

def test_retrieve_called_with_auth_headers(runner: CliRunner) -> None:
expected_auth_header = {"Authorization": "api-key fake-api-key-value"}
with unittest.mock.patch(
"stac_api_validator.validations.retrieve"
) as retrieve_mock:
runner.invoke(
__main__.main,
args=[
"--root-url",
"https://invalid",
"--conformance",
"core",
"--auth-headers",
f"{expected_auth_header}",
],
)
assert retrieve_mock.call_count == 1
r_session = retrieve_mock.call_args.args[-1]
assert (
r_session.headers["Authorization"] == expected_auth_header["Authorization"]
)
with suppress_type_checks():
with unittest.mock.patch(
"stac_api_validator.validations.retrieve"
) as retrieve_mock:
runner.invoke(
__main__.main,
args=[
"--root-url",
"https://invalid",
"--conformance",
"core",
"--auth-headers",
f"{expected_auth_header}",
],
)
assert retrieve_mock.call_count == 1
r_session = retrieve_mock.call_args.args[-1]
assert (
r_session.headers["Authorization"]
== expected_auth_header["Authorization"]
)

0 comments on commit 773a0e0

Please sign in to comment.