Files
gitea-codex/tests/test_main_env_validation.py
Space-Banane 7bc6165fff
All checks were successful
ci / test (push) Successful in 37s
ci / publish (push) Successful in 52s
[fix]. Validate required startup secrets
2026-05-23 00:06:02 +02:00

45 lines
1.5 KiB
Python

from __future__ import annotations
import pytest
from gitea_codex_bot.config import get_settings
from gitea_codex_bot.main import _validate_required_env
@pytest.mark.parametrize(
("env_name", "env_value", "error_text"),
[
("GITEA_WEBHOOK_SECRET", " ", "GITEA_WEBHOOK_SECRET is required"),
("GITEA_TOKEN", " ", "GITEA_TOKEN is required"),
("ALLOWED_REPOS", " ", "ALLOWED_REPOS is required"),
],
)
def test_validate_required_env_fails_on_blank_required_settings(
monkeypatch: pytest.MonkeyPatch, env_name: str, env_value: str, error_text: str
) -> None:
monkeypatch.setenv(env_name, env_value)
get_settings.cache_clear()
settings = get_settings()
with pytest.raises(RuntimeError, match=error_text):
_validate_required_env(settings)
def test_validate_required_env_requires_api_key_in_api_key_mode(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("OPENAI_API_KEY", "")
monkeypatch.setenv("CODEX_AUTH_MODE", "api_key")
get_settings.cache_clear()
settings = get_settings()
with pytest.raises(RuntimeError, match="OPENAI_API_KEY is required"):
_validate_required_env(settings)
def test_validate_required_env_allows_missing_key_in_chatgpt_mode(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("OPENAI_API_KEY", "")
monkeypatch.setenv("CODEX_AUTH_MODE", "chatgpt")
get_settings.cache_clear()
settings = get_settings()
_validate_required_env(settings)