Добавлены все базовые файлы для запуска проекта
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import pytest
|
||||
|
||||
import config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def env_file(tmp_path, monkeypatch):
|
||||
for name in tuple(config.os.environ):
|
||||
if name.startswith("N8N_"):
|
||||
monkeypatch.delenv(name)
|
||||
path = tmp_path / ".env"
|
||||
monkeypatch.setattr(config, "ENV_FILE", path)
|
||||
return path
|
||||
|
||||
|
||||
def test_file_loads_from_other_working_directory(env_file, tmp_path, monkeypatch):
|
||||
env_file.write_text(
|
||||
'N8N_CHAT_WEBHOOK_URL="https://example.com/chat"\n'
|
||||
'N8N_UPLOAD_WEBHOOK_URL=https://example.com/upload\n'
|
||||
'N8N_CHAT_TIMEOUT_SECONDS=15\nN8N_MAX_FILE_BYTES=2048\n',
|
||||
encoding="utf-8-sig",
|
||||
)
|
||||
elsewhere = tmp_path / "elsewhere"
|
||||
elsewhere.mkdir()
|
||||
monkeypatch.chdir(elsewhere)
|
||||
settings = config.Settings.from_env()
|
||||
assert settings.chat_webhook_url == "https://example.com/chat"
|
||||
assert settings.upload_webhook_url == "https://example.com/upload"
|
||||
assert settings.chat_timeout_seconds == 15
|
||||
assert settings.max_file_bytes == 2048
|
||||
|
||||
|
||||
def test_environment_overrides_file(env_file, monkeypatch):
|
||||
env_file.write_text("N8N_CHAT_WEBHOOK_URL=https://example.com/file\n")
|
||||
monkeypatch.setenv("N8N_CHAT_WEBHOOK_URL", "https://example.com/environment")
|
||||
assert config.Settings.from_env().chat_webhook_url.endswith("/environment")
|
||||
|
||||
|
||||
def test_missing_file_uses_defaults(env_file):
|
||||
assert config.Settings.from_env() == config.Settings()
|
||||
|
||||
|
||||
def test_invalid_file_setting_has_friendly_error(env_file):
|
||||
env_file.write_text("N8N_CHAT_TIMEOUT_SECONDS=abc\n")
|
||||
with pytest.raises(config.ConfigurationError, match="числовые"):
|
||||
config.Settings.from_env()
|
||||
Reference in New Issue
Block a user