Skip to content

Commit 3710540

Browse files
committed
Add a test to ensure auth headers arg works
1 parent 9aebd40 commit 3710540

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/stac_api_validator/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
)
6767
@click.option(
6868
"--auth-headers",
69-
help="Basic auth to attach to the request, e.g., {'Authorization': 'api-key=<api-key>'}",
69+
help="Auth headers to attach to the request, e.g., {'Authorization': 'api-key <api-key>'}",
7070
)
7171
def main(
7272
log_level: str,

src/stac_api_validator/validations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ def validate_browseable(
745745
Context.BROWSEABLE,
746746
params={
747747
"ids": item.id,
748-
"collections": getattr(item, "collection", None) or getattr(item, "collection_id", None)
748+
"collections": getattr(item, "collection", None)
749+
or getattr(item, "collection_id", None),
749750
},
750751
r_session=r_session,
751752
)

tests/test_main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Test cases for the __main__ module."""
2+
import unittest.mock
3+
24
import pytest
35
from click.testing import CliRunner
46

@@ -14,3 +16,26 @@ def runner() -> CliRunner:
1416
def test_main_fails(runner: CliRunner) -> None:
1517
result = runner.invoke(__main__.main)
1618
assert result.exit_code == 2
19+
20+
21+
def test_retrieve_called_with_auth_headers(runner: CliRunner) -> None:
22+
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+
)

0 commit comments

Comments
 (0)