76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from app.config import Settings, get_settings
|
|
|
|
|
|
REQUIRED_ENV = {
|
|
"NEXTCLOUD_WEBDAV_URL": "https://nc/remote.php/dav/files/u",
|
|
"NEXTCLOUD_USER": "u",
|
|
"NEXTCLOUD_APP_PASSWORD": "pw",
|
|
"OLLAMA_URL": "http://ollama:11434",
|
|
"OLLAMA_EMBED_MODEL": "qwen3-embedding:0.6b",
|
|
"QDRANT_URL": "http://qdrant:6333",
|
|
"QDRANT_COLLECTION": "rag_test",
|
|
"WEBHOOK_SECRET": "secret",
|
|
}
|
|
|
|
|
|
def _set_required(monkeypatch):
|
|
for k, v in REQUIRED_ENV.items():
|
|
monkeypatch.setenv(k, v)
|
|
|
|
|
|
def test_settings_loads_all_required_fields(monkeypatch):
|
|
_set_required(monkeypatch)
|
|
|
|
s = Settings()
|
|
|
|
assert s.nextcloud_webdav_url == REQUIRED_ENV["NEXTCLOUD_WEBDAV_URL"]
|
|
assert s.nextcloud_user == REQUIRED_ENV["NEXTCLOUD_USER"]
|
|
assert s.nextcloud_app_password == REQUIRED_ENV["NEXTCLOUD_APP_PASSWORD"]
|
|
assert s.ollama_url == REQUIRED_ENV["OLLAMA_URL"]
|
|
assert s.ollama_embed_model == REQUIRED_ENV["OLLAMA_EMBED_MODEL"]
|
|
assert s.qdrant_url == REQUIRED_ENV["QDRANT_URL"]
|
|
assert s.qdrant_collection == REQUIRED_ENV["QDRANT_COLLECTION"]
|
|
assert s.webhook_secret == REQUIRED_ENV["WEBHOOK_SECRET"]
|
|
# defaults
|
|
assert s.ingest_root == "Documents/THB/Studium"
|
|
assert s.chunk_size_words == 500
|
|
assert s.chunk_overlap_words == 50
|
|
assert s.log_level == "INFO"
|
|
|
|
|
|
def test_settings_overrides_defaults(monkeypatch):
|
|
_set_required(monkeypatch)
|
|
monkeypatch.setenv("INGEST_ROOT", "Other/Path")
|
|
monkeypatch.setenv("CHUNK_SIZE_WORDS", "300")
|
|
monkeypatch.setenv("CHUNK_OVERLAP_WORDS", "30")
|
|
|
|
s = Settings()
|
|
|
|
assert s.ingest_root == "Other/Path"
|
|
assert s.chunk_size_words == 300
|
|
assert s.chunk_overlap_words == 30
|
|
|
|
|
|
def test_settings_missing_required_raises(monkeypatch):
|
|
for k in REQUIRED_ENV:
|
|
monkeypatch.delenv(k, raising=False)
|
|
|
|
with pytest.raises(ValidationError):
|
|
Settings()
|
|
|
|
|
|
def test_get_settings_caches_instance(monkeypatch):
|
|
_set_required(monkeypatch)
|
|
get_settings.cache_clear()
|
|
|
|
first = get_settings()
|
|
second = get_settings()
|
|
|
|
assert isinstance(first, Settings)
|
|
assert first is second
|
|
|
|
get_settings.cache_clear()
|