CI / ruff · mypy · pytest (pull_request) Successful in 1m38s
У Settings нет префикса env, поэтому переменная CI=true с раннера Gitea попадала в поле ci и роняла создание настроек во всех тестах. Refs #11 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from app.config import AccessSettings, Settings
|
|
from app.texts import load_texts
|
|
|
|
|
|
def test_admin_ids_parsed_from_comma_separated_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("ADMIN_IDS", "1, 2,3,")
|
|
assert AccessSettings(_env_file=None).admin_ids == frozenset({1, 2, 3}) # type: ignore[call-arg]
|
|
|
|
|
|
def test_admin_ids_default_empty(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.delenv("ADMIN_IDS", raising=False)
|
|
assert AccessSettings(_env_file=None).admin_ids == frozenset() # type: ignore[call-arg]
|
|
|
|
|
|
def test_texts_with_missing_key_fail_fast(tmp_path: Path) -> None:
|
|
(tmp_path / "texts.yaml").write_text("menu: {commit: x}\n", encoding="utf-8")
|
|
with pytest.raises(ValidationError):
|
|
load_texts(tmp_path)
|
|
|
|
|
|
def test_ci_runner_env_does_not_break_settings(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
# Gitea/GitHub runners export CI=true; it must not collide with a settings field
|
|
monkeypatch.setenv("CI", "true")
|
|
monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "42:x")
|
|
|
|
assert Settings().uploads_ci.provider == "none"
|