30 lines
811 B
Python
30 lines
811 B
Python
|
|
"""Tests for Honcho CLI helpers."""
|
||
|
|
|
||
|
|
from honcho_integration.cli import _resolve_api_key
|
||
|
|
|
||
|
|
|
||
|
|
class TestResolveApiKey:
|
||
|
|
def test_prefers_host_scoped_key(self):
|
||
|
|
cfg = {
|
||
|
|
"apiKey": "root-key",
|
||
|
|
"hosts": {
|
||
|
|
"hermes": {
|
||
|
|
"apiKey": "host-key",
|
||
|
|
}
|
||
|
|
},
|
||
|
|
}
|
||
|
|
assert _resolve_api_key(cfg) == "host-key"
|
||
|
|
|
||
|
|
def test_falls_back_to_root_key(self):
|
||
|
|
cfg = {
|
||
|
|
"apiKey": "root-key",
|
||
|
|
"hosts": {"hermes": {}},
|
||
|
|
}
|
||
|
|
assert _resolve_api_key(cfg) == "root-key"
|
||
|
|
|
||
|
|
def test_falls_back_to_env_key(self, monkeypatch):
|
||
|
|
monkeypatch.setenv("HONCHO_API_KEY", "env-key")
|
||
|
|
assert _resolve_api_key({}) == "env-key"
|
||
|
|
monkeypatch.delenv("HONCHO_API_KEY", raising=False)
|
||
|
|
|