Skip to content

Commit 773a0e0

Browse files
committed
Fix mypy and suppress type checks for mocked test
1 parent cfc4731 commit 773a0e0

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

poetry.lock

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/stac_api_validator/validations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def is_geojson_type(maybe_type: Optional[str]) -> bool:
279279
def get_catalog(data_dict: Dict[str, Any], r_session: Session) -> Catalog:
280280
stac_io = StacIO.default()
281281
if r_session.headers and r_session.headers.get("Authorization"):
282-
stac_io.headers = {"Authorization": r_session.headers["Authorization"]}
282+
stac_io.headers = {"Authorization": str(r_session.headers["Authorization"])}
283283
catalog = Catalog.from_dict(data_dict)
284284
catalog._stac_io = stac_io
285285
return catalog
@@ -598,7 +598,7 @@ def validate_api(
598598
try:
599599
headers = {}
600600
if r_session.headers and r_session.headers.get("Authorization"):
601-
headers["Authorization"] = r_session.headers["Authorization"]
601+
headers["Authorization"] = str(r_session.headers["Authorization"])
602602
catalog = Client.open(root_url, headers=headers)
603603
catalog.validate()
604604
for child in catalog.get_children():

tests/test_main.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
from click.testing import CliRunner
6+
from typeguard import suppress_type_checks
67

78
from stac_api_validator import __main__
89

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

2122
def test_retrieve_called_with_auth_headers(runner: CliRunner) -> None:
2223
expected_auth_header = {"Authorization": "api-key fake-api-key-value"}
23-
with unittest.mock.patch(
24-
"stac_api_validator.validations.retrieve"
25-
) as retrieve_mock:
26-
runner.invoke(
27-
__main__.main,
28-
args=[
29-
"--root-url",
30-
"https://invalid",
31-
"--conformance",
32-
"core",
33-
"--auth-headers",
34-
f"{expected_auth_header}",
35-
],
36-
)
37-
assert retrieve_mock.call_count == 1
38-
r_session = retrieve_mock.call_args.args[-1]
39-
assert (
40-
r_session.headers["Authorization"] == expected_auth_header["Authorization"]
41-
)
24+
with suppress_type_checks():
25+
with unittest.mock.patch(
26+
"stac_api_validator.validations.retrieve"
27+
) as retrieve_mock:
28+
runner.invoke(
29+
__main__.main,
30+
args=[
31+
"--root-url",
32+
"https://invalid",
33+
"--conformance",
34+
"core",
35+
"--auth-headers",
36+
f"{expected_auth_header}",
37+
],
38+
)
39+
assert retrieve_mock.call_count == 1
40+
r_session = retrieve_mock.call_args.args[-1]
41+
assert (
42+
r_session.headers["Authorization"]
43+
== expected_auth_header["Authorization"]
44+
)

0 commit comments

Comments
 (0)