64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
import pytest
|
|
|
|
from app.config import Settings
|
|
from app.errors import ConfigError
|
|
|
|
|
|
def test_defaults():
|
|
s = Settings(_env_file=None)
|
|
assert s.comfy_base_url == "http://192.168.0.3:8188"
|
|
assert s.execution_timeout == 300.0
|
|
assert s.poll_interval == 1.5
|
|
assert s.models_file.name == "models.json"
|
|
|
|
|
|
def test_env_override(monkeypatch):
|
|
monkeypatch.setenv("COMFY_BASE_URL", "http://example:9000")
|
|
monkeypatch.setenv("ADAPTER_API_KEY", "sk-abc")
|
|
monkeypatch.setenv("EXECUTION_TIMEOUT", "42")
|
|
monkeypatch.setenv("POLL_INTERVAL", "0.5")
|
|
s = Settings(_env_file=None)
|
|
assert s.comfy_base_url == "http://example:9000"
|
|
assert s.adapter_api_key == "sk-abc"
|
|
assert s.execution_timeout == 42.0
|
|
assert s.poll_interval == 0.5
|
|
|
|
|
|
def test_registry_loads_shipped_in_order():
|
|
s = Settings(_env_file=None)
|
|
registry = s.load_registry()
|
|
# order preserved (first = preferred for default selection)
|
|
assert list(registry) == ["z-image-turbo", "qwen-image-edit"]
|
|
assert registry["z-image-turbo"].workflow.name == "z_image_turbo.json"
|
|
assert registry["z-image-turbo"].owned_by == "comfy-adapter"
|
|
|
|
|
|
def test_registry_missing_file_fails_fast(tmp_path):
|
|
s = Settings(_env_file=None, models_file=tmp_path / "nope.json")
|
|
with pytest.raises(ConfigError, match="not found"):
|
|
s.load_registry()
|
|
|
|
|
|
def test_registry_malformed_json_fails_fast(tmp_path):
|
|
f = tmp_path / "models.json"
|
|
f.write_text("{not valid", encoding="utf-8")
|
|
s = Settings(_env_file=None, models_file=f)
|
|
with pytest.raises(ConfigError, match="not valid JSON"):
|
|
s.load_registry()
|
|
|
|
|
|
def test_registry_empty_fails_fast(tmp_path):
|
|
f = tmp_path / "models.json"
|
|
f.write_text("{}", encoding="utf-8")
|
|
s = Settings(_env_file=None, models_file=f)
|
|
with pytest.raises(ConfigError, match="non-empty"):
|
|
s.load_registry()
|
|
|
|
|
|
def test_registry_bad_entry_fails_fast(tmp_path):
|
|
f = tmp_path / "models.json"
|
|
f.write_text('{"m": {"not_workflow": "x.json"}}', encoding="utf-8")
|
|
s = Settings(_env_file=None, models_file=f)
|
|
with pytest.raises(ConfigError, match="invalid entry"):
|
|
s.load_registry()
|