Refactor configuration handling and improve error management across services; normalize placeholder values for SMTP and Stripe configurations; enhance local storage fallback logic in StorageService; add tests for new behaviors and edge cases.

This commit is contained in:
Your Name
2026-03-26 14:15:10 +02:00
parent 688d411537
commit bc8a5dc290
19 changed files with 423 additions and 95 deletions

View File

@@ -1,6 +1,10 @@
"""Tests for shared OpenRouter configuration resolution across AI services."""
from app.services.openrouter_config_service import get_openrouter_settings
from app.services.openrouter_config_service import (
LEGACY_SAMPLE_OPENROUTER_API_KEY,
extract_openrouter_text,
get_openrouter_settings,
)
from app.services.pdf_ai_service import _call_openrouter
from app.services.site_assistant_service import _request_ai_reply
@@ -85,7 +89,7 @@ class TestOpenRouterConfigService:
monkeypatch.setattr(
'app.services.openrouter_config_service._load_dotenv_settings',
lambda: {
'OPENROUTER_API_KEY': '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',
'OPENROUTER_API_KEY': LEGACY_SAMPLE_OPENROUTER_API_KEY,
},
)
@@ -95,6 +99,27 @@ class TestOpenRouterConfigService:
assert settings.api_key == ''
def test_extract_openrouter_text_supports_string_and_list_content(self):
assert extract_openrouter_text({
'choices': [{'message': {'content': ' plain text reply '}}],
}) == 'plain text reply'
assert extract_openrouter_text({
'choices': [{
'message': {
'content': [
{'type': 'text', 'text': 'First part'},
{'type': 'text', 'content': 'Second part'},
None,
],
},
}],
}) == 'First part\nSecond part'
assert extract_openrouter_text({
'choices': [{'message': {'content': None}}],
}) == ''
class TestAiServicesUseSharedConfig:
def test_pdf_ai_uses_flask_config(self, app, monkeypatch):
@@ -166,4 +191,4 @@ class TestAiServicesUseSharedConfig:
assert captured['headers']['Authorization'] == 'Bearer assistant-key'
assert captured['json']['model'] == 'assistant-model'
assert captured['json']['messages'][-1] == {'role': 'user', 'content': 'How do I merge files?'}
assert captured['usage']['model'] == 'assistant-model'
assert captured['usage']['model'] == 'assistant-model'