Investment_Assistant / tests /test_integration.py
Egeekle's picture
Add MLOps, RAG, monitoring, and utility dependencies to requirements.txt
7a658e1
"""
Integration tests for Investment Assistant
"""
import pytest
import asyncio
import sys
import os
# Add parent directory to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
class TestAPIIntegration:
"""Test API integration"""
@pytest.mark.asyncio
async def test_market_data_fetch(self):
"""Test fetching market data"""
from main import get_market_data
# Test with crypto (no API key needed)
result = await get_market_data(["bitcoin"], "CRYPTO")
assert "bitcoin" in result
# Should have price data
if "error" not in result["bitcoin"]:
assert "current_price" in result["bitcoin"]
assert "prices" in result["bitcoin"]
def test_strategy_generation(self):
"""Test strategy generation"""
from main import generate_top_bottom_strategy
# Mock market data
market_data = {
"current_price": 100,
"prices": [95, 98, 100, 102, 105, 100, 98, 100],
"high_30d": 105,
"low_30d": 95,
"change_30d": 5.0
}
strategy = generate_top_bottom_strategy("SPY", "ETF", market_data)
assert "symbol" in strategy
assert "top_strategy" in strategy
assert "bottom_strategy" in strategy
assert strategy["symbol"] == "SPY"
class TestAgentIntegration:
"""Test Agent integration"""
def test_rag_system_with_agent(self):
"""Test RAG system integration with agent"""
from unittest.mock import Mock
from src.agents.investment_agent import InvestmentAgent
from src.agents.rag_system import RAGSystem
mock_openai = Mock()
rag = RAGSystem(mock_openai)
agent = InvestmentAgent(mock_openai, rag)
assert agent.rag_system == rag
def test_agent_context_enhancement(self):
"""Test agent context enhancement with RAG"""
from unittest.mock import Mock
from src.agents.investment_agent import InvestmentAgent
mock_openai = Mock()
agent = InvestmentAgent(mock_openai)
market_data = {
"current_price": 100,
"prices": [95, 100, 105]
}
context = agent.rag_system.get_enhanced_context("What is TOP strategy?", market_data)
assert isinstance(context, str)
assert len(context) > 0
class TestMonitoringIntegration:
"""Test Monitoring integration"""
def test_monitoring_with_predictions(self):
"""Test monitoring with predictions"""
import pandas as pd
import numpy as np
from src.monitoring.monitoring_service import MonitoringService
service = MonitoringService()
# Initialize reference baseline
reference_data = pd.DataFrame({
'price': np.random.normal(100, 10, 100),
'rsi': np.random.normal(50, 10, 100)
})
service.initialize_reference_baseline(reference_data)
# Current data
current_data = pd.DataFrame({
'price': np.random.normal(100, 10, 50),
'rsi': np.random.normal(50, 10, 50)
})
prediction = {
"score": 0.75,
"recommendation": "BUY"
}
service.monitor_prediction("SPY", "TOP", prediction, current_data)
# Check health report
health = service.get_health_report()
assert "status" in health
if __name__ == "__main__":
pytest.main([__file__, "-v"])