feat: add multi-chat routing and bill-specific dashboard countdown
Some checks failed
Test blackout notifier / test (push) Failing after 4s
Hourly blackout check / check (push) Successful in 3s

This commit is contained in:
Meghdad
2026-07-22 02:14:45 +03:30
parent 6c3e146234
commit 42687ee651
12 changed files with 372 additions and 100 deletions

View File

@@ -7,8 +7,7 @@ from blackout_notifier.config import Config, ConfigurationError
REQUIRED = {
"BARGHEMAN_TOKEN": "bargheman",
"EITAAYAR_TOKEN": "eitaayar",
"CHAT_ID": "chat",
"BILL_IDS": " 123,456,123 ,, ",
"BILL_CHAT_MAP": " 123:chat-a,456:chat-b,123:chat-c,123:chat-a ,, ",
}
@@ -17,13 +16,17 @@ def do_not_load_project_dotenv(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr("blackout_notifier.config.load_dotenv", lambda **_: None)
def test_config_parses_and_deduplicates_bill_ids(monkeypatch: pytest.MonkeyPatch) -> None:
def test_config_parses_and_deduplicates_bill_routes(monkeypatch: pytest.MonkeyPatch) -> None:
for name, value in REQUIRED.items():
monkeypatch.setenv(name, value)
config = Config.from_env()
assert config.bill_ids == ("123", "456")
assert dict(config.bill_chat_ids) == {
"123": ("chat-a", "chat-c"),
"456": ("chat-b",),
}
assert str(config.state_file) == "state/outages.json"
assert config.lookahead_days == 5
@@ -40,12 +43,39 @@ def test_config_reports_all_missing_required_values(monkeypatch: pytest.MonkeyPa
def test_config_rejects_non_decimal_bill_ids(monkeypatch: pytest.MonkeyPatch) -> None:
for name, value in REQUIRED.items():
monkeypatch.setenv(name, value)
monkeypatch.setenv("BILL_IDS", "123,761/pe9314604429")
monkeypatch.setenv("BILL_CHAT_MAP", "123:chat-a,761/pe9314604429:chat-b")
with pytest.raises(ConfigurationError, match="decimal IDs"):
with pytest.raises(ConfigurationError, match="bill IDs must be decimal"):
Config.from_env()
def test_config_rejects_malformed_routes(
monkeypatch: pytest.MonkeyPatch,
) -> None:
for name, value in REQUIRED.items():
monkeypatch.setenv(name, value)
monkeypatch.setenv("BILL_CHAT_MAP", "123")
with pytest.raises(ConfigurationError, match="BILL_ID:CHAT_ID"):
Config.from_env()
def test_legacy_single_chat_configuration_is_still_supported(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setenv("BARGHEMAN_TOKEN", "bargheman")
monkeypatch.setenv("EITAAYAR_TOKEN", "eitaayar")
monkeypatch.setenv("CHAT_ID", "legacy-chat")
monkeypatch.setenv("BILL_IDS", "123,456,123")
monkeypatch.delenv("BILL_CHAT_MAP", raising=False)
config = Config.from_env()
assert dict(config.bill_chat_ids) == {
"123": ("legacy-chat",),
"456": ("legacy-chat",),
}
def test_config_validates_numeric_ranges(monkeypatch: pytest.MonkeyPatch) -> None:
for name, value in REQUIRED.items():
monkeypatch.setenv(name, value)