Spaces:
Running
Running
Create test_ai_system.py
Browse files- tests/test_ai_system.py +51 -0
tests/test_ai_system.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Add src to path
|
| 6 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
| 7 |
+
|
| 8 |
+
from src.ai_system import SaemsTunesAISystem
|
| 9 |
+
from src.supabase_integration import SupabaseIntegration
|
| 10 |
+
from src.security_system import SecuritySystem
|
| 11 |
+
from src.monitoring_system import ComprehensiveMonitor
|
| 12 |
+
|
| 13 |
+
class TestAISystem:
|
| 14 |
+
"""Test AI system functionality"""
|
| 15 |
+
|
| 16 |
+
def setup_method(self):
|
| 17 |
+
"""Setup test fixtures"""
|
| 18 |
+
self.supabase = SupabaseIntegration("test_url", "test_key")
|
| 19 |
+
self.security = SecuritySystem()
|
| 20 |
+
self.monitor = ComprehensiveMonitor()
|
| 21 |
+
|
| 22 |
+
# Mock the model loading to avoid downloading
|
| 23 |
+
self.ai_system = SaemsTunesAISystem(self.supabase, self.security, self.monitor)
|
| 24 |
+
self.ai_system.model_loaded = True # Simulate loaded model
|
| 25 |
+
|
| 26 |
+
def test_process_query_basic(self):
|
| 27 |
+
"""Test basic query processing"""
|
| 28 |
+
response = self.ai_system.process_query("Hello", "test_user")
|
| 29 |
+
assert isinstance(response, str)
|
| 30 |
+
assert len(response) > 0
|
| 31 |
+
|
| 32 |
+
def test_build_prompt(self):
|
| 33 |
+
"""Test prompt building"""
|
| 34 |
+
context = {
|
| 35 |
+
"stats": {"song_count": 100, "artist_count": 10, "user_count": 1000},
|
| 36 |
+
"summary": "Test context"
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
prompt = self.ai_system.build_prompt("test question", context)
|
| 40 |
+
|
| 41 |
+
assert "test question" in prompt
|
| 42 |
+
assert "Test context" in prompt
|
| 43 |
+
assert "<|system|>" in prompt
|
| 44 |
+
assert "<|user|>" in prompt
|
| 45 |
+
|
| 46 |
+
def test_system_health(self):
|
| 47 |
+
"""Test system health check"""
|
| 48 |
+
assert self.ai_system.is_healthy() == True
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
pytest.main([__file__])
|