generated from john/python-template
Step 1 complete!
This commit is contained in:
+32
-2
@@ -1,16 +1,34 @@
|
||||
"""Tests for transcription.config — settings loading, provider defaults, and paths."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from transcription.config import Provider, Settings
|
||||
|
||||
|
||||
def _make_settings(**overrides) -> Settings:
|
||||
"""Build a Settings instance with a dummy API key unless overridden."""
|
||||
defaults = {"openrouter_api_key": "test-key-abc123"}
|
||||
defaults.update(overrides)
|
||||
return Settings(**defaults)
|
||||
|
||||
|
||||
class TestSettingsLoading:
|
||||
"""Verify Settings construction and required-field validation."""
|
||||
|
||||
def test_loads_from_env(self):
|
||||
def test_loads_from_env(self, monkeypatch):
|
||||
"""Settings constructs when OPENROUTER_API_KEY is provided."""
|
||||
monkeypatch.setenv("OPENROUTER_API_KEY", "test-key-xyz")
|
||||
settings = Settings()
|
||||
assert settings.openrouter_api_key == "test-key-xyz"
|
||||
|
||||
def test_requires_api_key(self):
|
||||
def test_requires_api_key(self, monkeypatch):
|
||||
"""Settings raises ValidationError when OPENROUTER_API_KEY is missing."""
|
||||
monkeypatch.delenv("OPENROUTER_API_KEY", raising=False)
|
||||
with pytest.raises(ValidationError):
|
||||
Settings(_env_file=None)
|
||||
|
||||
|
||||
class TestProviderSettings:
|
||||
@@ -18,12 +36,21 @@ class TestProviderSettings:
|
||||
|
||||
def test_defaults_to_openrouter(self):
|
||||
"""Default provider is openrouter when not explicitly set."""
|
||||
settings = _make_settings()
|
||||
assert settings.provider == Provider.OPENROUTER
|
||||
assert settings.provider == "openrouter"
|
||||
|
||||
def test_rejects_invalid_value(self):
|
||||
"""Setting PROVIDER to an invalid value raises ValidationError."""
|
||||
with pytest.raises(ValidationError):
|
||||
_make_settings(provider="not-a-provider")
|
||||
|
||||
def test_optional_fields_default_to_none(self):
|
||||
"""provider_model, openrouter_http_referer, and openrouter_app_title are None when unset."""
|
||||
settings = _make_settings()
|
||||
assert settings.provider_model is None
|
||||
assert settings.openrouter_http_referer is None
|
||||
assert settings.openrouter_app_title is None
|
||||
|
||||
|
||||
class TestPathSettings:
|
||||
@@ -31,3 +58,6 @@ class TestPathSettings:
|
||||
|
||||
def test_path_fields_are_path_objects(self):
|
||||
"""upload_dir and prompt_dir are Path instances."""
|
||||
settings = _make_settings()
|
||||
assert isinstance(settings.upload_dir, Path)
|
||||
assert isinstance(settings.prompt_dir, Path)
|
||||
|
||||
Reference in New Issue
Block a user