Add Telegram notifications, make Discord optional
This commit is contained in:
@@ -11,6 +11,8 @@ ENV_KEYS = [
|
||||
"DISCORD_WEBHOOK_URL",
|
||||
"DISCORD_SERVER_NAME",
|
||||
"DISCORD_ROLES",
|
||||
"TELEGRAM_BOT_TOKEN",
|
||||
"TELEGRAM_CHAT_ID",
|
||||
"COUNTRY",
|
||||
"REFRESH_TIME",
|
||||
"TEST_MODE",
|
||||
@@ -27,9 +29,28 @@ def _reload_env_config(monkeypatch, env):
|
||||
return importlib.import_module(MODULE_NAME)
|
||||
|
||||
|
||||
def test_missing_webhook_exits(monkeypatch):
|
||||
with pytest.raises(SystemExit):
|
||||
_reload_env_config(monkeypatch, {"PRODUCT_NAMES": "RTX 5090"})
|
||||
def test_no_notification_channel_does_not_exit(monkeypatch, caplog):
|
||||
cfg = _reload_env_config(monkeypatch, {"PRODUCT_NAMES": "RTX 5090"})
|
||||
assert not cfg.DISCORD_ENABLED
|
||||
assert not cfg.TELEGRAM_ENABLED
|
||||
assert "DISCORD IS NOT CONFIGURED" in caplog.text
|
||||
assert "TELEGRAM IS NOT CONFIGURED" in caplog.text
|
||||
|
||||
|
||||
def test_telegram_only_is_enabled(monkeypatch):
|
||||
cfg = _reload_env_config(
|
||||
monkeypatch,
|
||||
{"PRODUCT_NAMES": "RTX 5090", "TELEGRAM_BOT_TOKEN": "123:abc", "TELEGRAM_CHAT_ID": "-100"},
|
||||
)
|
||||
assert cfg.TELEGRAM_ENABLED
|
||||
assert not cfg.DISCORD_ENABLED
|
||||
|
||||
|
||||
def test_telegram_partial_config_is_disabled(monkeypatch):
|
||||
cfg = _reload_env_config(
|
||||
monkeypatch, {"PRODUCT_NAMES": "RTX 5090", "TELEGRAM_BOT_TOKEN": "123:abc"}
|
||||
)
|
||||
assert not cfg.TELEGRAM_ENABLED
|
||||
|
||||
|
||||
def test_missing_product_names_exits(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user