mitai-jinkendo/backend/tests/test_tandoor_client.py

49 lines
1.5 KiB
Python
Raw Permalink Normal View History

from data_layer.tandoor_client import TandoorError, normalize_base_url, public_settings, token_hint
def test_tandoor_router_imports():
from routers import tandoor
paths = {r.path for r in tandoor.router.routes}
assert "/api/tandoor/settings" in paths
assert "/api/tandoor/test" in paths
def test_normalize_https_strips_slash():
assert normalize_base_url("https://tandoor.stommer.de/") == "https://tandoor.stommer.de"
def test_normalize_rejects_empty_and_bare_host():
try:
normalize_base_url(" ")
except TandoorError as e:
assert "fehlt" in str(e)
else:
raise AssertionError("expected TandoorError")
try:
normalize_base_url("tandoor.stommer.de")
except TandoorError:
pass
else:
raise AssertionError("expected TandoorError")
def test_normalize_rejects_public_http():
try:
normalize_base_url("http://tandoor.stommer.de")
except TandoorError as e:
assert "https" in str(e)
else:
raise AssertionError("expected TandoorError")
def test_token_hint_never_full():
assert token_hint("abcdefghijklmnop") == "…mnop"
assert "abcd" not in (token_hint("secret-token-value") or "")
assert public_settings(None)["token_set"] is False
pub = public_settings({"base_url": "https://tandoor.example", "api_token": "super-secret-token"})
assert pub["token_set"] is True
assert pub["token_hint"] == "…oken"
assert "super" not in (pub["token_hint"] or "")
assert "api_token" not in pub