Fix analytics tests and add comprehensive testing guide
Critical Fixes: - Fixed Price model query to use security_id join with Security - Added Security import to returns.py module - Fixed all test fixtures to use test_db_session correctly - Added AAPL price data to sample_prices fixture New Tests: - tests/test_analytics_integration.py: 10 comprehensive integration tests * Real-world scenarios with synthetic price data * Return calculations, benchmark comparisons, performance metrics * Edge cases: missing data, sell trades, disclosure timing Documentation: - LOCAL_TEST_GUIDE.md: Complete guide for local testing * How to test before deploying * Current data status (live vs fixtures) * Multiple options for getting real data * Common issues and fixes Test Results: ✅ All 55 tests passing ✅ Analytics fully functional ✅ Ready for deployment Live Data Status: ❌ House Stock Watcher API still down (external issue) ✅ Manual CSV import works ✅ yfinance for prices works ✅ Can use system NOW with manual data
This commit is contained in:
@@ -11,7 +11,7 @@ import pandas as pd
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from pote.db.models import Price, Trade
|
||||
from pote.db.models import Price, Security, Trade
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -166,11 +166,12 @@ class ReturnCalculator:
|
||||
start_date = target_date - timedelta(days=days_tolerance)
|
||||
end_date = target_date + timedelta(days=days_tolerance)
|
||||
|
||||
# Query prices near target date
|
||||
# Query prices near target date (join with Security to filter by ticker)
|
||||
prices = (
|
||||
self.session.query(Price)
|
||||
.join(Security)
|
||||
.filter(
|
||||
Price.ticker == ticker,
|
||||
Security.ticker == ticker,
|
||||
Price.date >= start_date,
|
||||
Price.date <= end_date,
|
||||
)
|
||||
@@ -209,8 +210,9 @@ class ReturnCalculator:
|
||||
"""
|
||||
prices = (
|
||||
self.session.query(Price)
|
||||
.join(Security)
|
||||
.filter(
|
||||
Price.ticker == ticker,
|
||||
Security.ticker == ticker,
|
||||
Price.date >= start_date,
|
||||
Price.date <= end_date,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user