fix: accept CSV telegram ID config (#27)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
"""Tests for Steward configuration loading."""
|
||||
|
||||
import pytest
|
||||
|
||||
from steward import config as config_module
|
||||
from steward.config import TelegramConfig, reload_settings
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_settings_singleton():
|
||||
config_module._settings_instance = None
|
||||
yield
|
||||
config_module._settings_instance = None
|
||||
|
||||
|
||||
def test_telegram_config_accepts_csv_id_lists():
|
||||
config = TelegramConfig(
|
||||
allowed_user_ids="8861600138, 123456789",
|
||||
group_ids="-5308306472,-1005308306472",
|
||||
)
|
||||
|
||||
assert config.allowed_user_ids == [8861600138, 123456789]
|
||||
assert config.group_ids == [-5308306472, -1005308306472]
|
||||
|
||||
|
||||
def test_telegram_config_preserves_list_id_values():
|
||||
config = TelegramConfig(
|
||||
allowed_user_ids=[8861600138, 123456789],
|
||||
group_ids=[-5308306472, -1005308306472],
|
||||
)
|
||||
|
||||
assert config.allowed_user_ids == [8861600138, 123456789]
|
||||
assert config.group_ids == [-5308306472, -1005308306472]
|
||||
|
||||
|
||||
def test_settings_accepts_csv_id_lists_from_env(monkeypatch):
|
||||
monkeypatch.setenv("STEWARD__TELEGRAM__ALLOWED_USER_IDS", "8861600138,123456789")
|
||||
monkeypatch.setenv("STEWARD__TELEGRAM__GROUP_IDS", "-5308306472,-1005308306472")
|
||||
|
||||
settings = reload_settings()
|
||||
|
||||
assert settings.telegram_allowed_user_ids == [8861600138, 123456789]
|
||||
assert settings.telegram_group_ids == [-5308306472, -1005308306472]
|
||||
|
||||
|
||||
def test_settings_accepts_single_id_values_from_env(monkeypatch):
|
||||
monkeypatch.setenv("STEWARD__TELEGRAM__ALLOWED_USER_IDS", "8861600138")
|
||||
monkeypatch.setenv("STEWARD__TELEGRAM__GROUP_IDS", "-5308306472")
|
||||
|
||||
settings = reload_settings()
|
||||
|
||||
assert settings.telegram_allowed_user_ids == [8861600138]
|
||||
assert settings.telegram_group_ids == [-5308306472]
|
||||
|
||||
|
||||
def test_settings_accepts_quoted_json_id_lists_from_env(monkeypatch):
|
||||
monkeypatch.setenv("STEWARD__TELEGRAM__ALLOWED_USER_IDS", "'[8861600138]'")
|
||||
monkeypatch.setenv("STEWARD__TELEGRAM__GROUP_IDS", "'[-5308306472]'")
|
||||
|
||||
settings = reload_settings()
|
||||
|
||||
assert settings.telegram_allowed_user_ids == [8861600138]
|
||||
assert settings.telegram_group_ids == [-5308306472]
|
||||
Reference in New Issue
Block a user