42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from property_bot.config import load_config
|
|
|
|
|
|
def write_config(path: Path, websocket_url: str = "ws://127.0.0.1:3000/ws") -> None:
|
|
path.write_text(
|
|
f'''[telegram]
|
|
api_id = 1
|
|
api_hash = "hash"
|
|
bot_token = "token"
|
|
[admins]
|
|
user_ids = [10, 20]
|
|
[property_api]
|
|
websocket_url = "{websocket_url}"
|
|
connect_timeout_seconds = 15
|
|
reconnect_initial_delay_seconds = 1
|
|
reconnect_max_delay_seconds = 30
|
|
[database]
|
|
path = "data/bot.sqlite3"
|
|
''',
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
def test_loads_valid_toml_config(tmp_path: Path) -> None:
|
|
path = tmp_path / "config.toml"
|
|
write_config(path)
|
|
config = load_config(path)
|
|
assert config.telegram.api_id == 1
|
|
assert config.admin_user_ids == frozenset({10, 20})
|
|
assert config.property_api.websocket_url == "ws://127.0.0.1:3000/ws"
|
|
|
|
|
|
def test_rejects_non_websocket_url(tmp_path: Path) -> None:
|
|
path = tmp_path / "config.toml"
|
|
write_config(path, "http://127.0.0.1:3000/ws")
|
|
with pytest.raises(ValueError, match="ws://"):
|
|
load_config(path)
|