56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from doctor_workstation.config import AppConfig, normalize_api_base_url
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("raw", "expected"),
|
|
[
|
|
("https://api.example.com", "https://api.example.com/adminapi"),
|
|
("https://api.example.com/", "https://api.example.com/adminapi"),
|
|
("https://api.example.com/adminapi", "https://api.example.com/adminapi"),
|
|
("http://127.0.0.1:8080/gateway", "http://127.0.0.1:8080/gateway/adminapi"),
|
|
("", ""),
|
|
],
|
|
)
|
|
def test_normalize_api_base_url(raw: str, expected: str) -> None:
|
|
assert normalize_api_base_url(raw) == expected
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"raw",
|
|
["api.example.com", "ftp://api.example.com", "https://u:p@example.com", "https://x.test?a=1"],
|
|
)
|
|
def test_normalize_api_base_url_rejects_unsafe_values(raw: str) -> None:
|
|
with pytest.raises(ValueError):
|
|
normalize_api_base_url(raw)
|
|
|
|
|
|
def test_config_update_validates_video_mode() -> None:
|
|
with pytest.raises(ValueError):
|
|
AppConfig().with_updates(video_mode="unknown")
|
|
|
|
|
|
def test_config_update_normalizes_ssl_boolean_strings() -> None:
|
|
assert AppConfig().with_updates(verify_ssl="false").verify_ssl is False
|
|
assert AppConfig(verify_ssl=False).with_updates(verify_ssl="true").verify_ssl is True
|
|
|
|
|
|
def test_runtime_directories_can_be_isolated_without_replacing_user_home(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
tmp_path: Path,
|
|
) -> None:
|
|
config_dir = tmp_path / "config"
|
|
log_dir = tmp_path / "logs"
|
|
monkeypatch.setenv("DOCTOR_CONFIG_DIR", str(config_dir))
|
|
monkeypatch.setenv("DOCTOR_LOG_DIR", str(log_dir))
|
|
|
|
config = AppConfig()
|
|
|
|
assert config.config_dir == config_dir
|
|
assert config.log_dir == log_dir
|