initial commit
This commit is contained in:
58
backend/tests/test_llm_service.py
Normal file
58
backend/tests/test_llm_service.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""FluentGerman.ai — LLM service tests (mocked)."""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.instruction_service import get_system_prompt
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_system_prompt_empty():
|
||||
"""When no instructions exist, returns default prompt."""
|
||||
db = AsyncMock()
|
||||
# Mock two queries returning empty results
|
||||
mock_result = MagicMock()
|
||||
mock_result.scalars.return_value.all.return_value = []
|
||||
db.execute = AsyncMock(return_value=mock_result)
|
||||
|
||||
prompt = await get_system_prompt(db, user_id=1)
|
||||
assert "German" in prompt
|
||||
assert "tutor" in prompt.lower()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_system_prompt_with_instructions():
|
||||
"""System prompt includes global and personal instructions."""
|
||||
from app.models import Instruction, InstructionType
|
||||
|
||||
global_inst = MagicMock()
|
||||
global_inst.title = "Method"
|
||||
global_inst.content = "Use immersive conversation"
|
||||
global_inst.type = InstructionType.GLOBAL
|
||||
|
||||
personal_inst = MagicMock()
|
||||
personal_inst.title = "Focus"
|
||||
personal_inst.content = "Practice articles"
|
||||
personal_inst.type = InstructionType.PERSONAL
|
||||
|
||||
db = AsyncMock()
|
||||
call_count = 0
|
||||
|
||||
async def mock_execute(query):
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
result = MagicMock()
|
||||
if call_count == 1:
|
||||
result.scalars.return_value.all.return_value = [global_inst]
|
||||
else:
|
||||
result.scalars.return_value.all.return_value = [personal_inst]
|
||||
return result
|
||||
|
||||
db.execute = mock_execute
|
||||
|
||||
prompt = await get_system_prompt(db, user_id=1)
|
||||
assert "TEACHING METHOD" in prompt
|
||||
assert "immersive conversation" in prompt
|
||||
assert "PERSONAL INSTRUCTIONS" in prompt
|
||||
assert "Practice articles" in prompt
|
||||
Reference in New Issue
Block a user