45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from tgbridge.config import ConfigError, load_config
|
|
|
|
|
|
def test_load_config_from_env():
|
|
config = load_config(
|
|
env={
|
|
"COMFY_TG_BOT_TOKEN": "token",
|
|
"COMFY_TG_CHAT_ID": "-100123",
|
|
"COMFY_TG_DISABLE_NOTIFICATION": "true",
|
|
"COMFY_TG_MESSAGE_THREAD_ID": "7",
|
|
"COMFY_TG_TIMEOUT_SECONDS": "30",
|
|
}
|
|
)
|
|
|
|
assert config.bot_token == "token"
|
|
assert config.chat_id == "-100123"
|
|
assert config.disable_notification is True
|
|
assert config.message_thread_id == 7
|
|
assert config.timeout_seconds == 30
|
|
|
|
|
|
def test_env_overrides_config_file(tmp_path):
|
|
config_path = tmp_path / "telegram.json"
|
|
config_path.write_text(
|
|
json.dumps({"bot_token": "file-token", "chat_id": "file-chat"}),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
config = load_config(
|
|
config_path=config_path,
|
|
env={"COMFY_TG_BOT_TOKEN": "env-token", "COMFY_TG_CHAT_ID": "env-chat"},
|
|
)
|
|
|
|
assert config.bot_token == "env-token"
|
|
assert config.chat_id == "env-chat"
|
|
|
|
|
|
def test_missing_required_config_raises(tmp_path):
|
|
with pytest.raises(ConfigError, match="COMFY_TG_BOT_TOKEN"):
|
|
load_config(config_path=tmp_path / "missing.json", env={})
|