-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_shadowwatch_integration.py
More file actions
137 lines (122 loc) · 4.56 KB
/
test_shadowwatch_integration.py
File metadata and controls
137 lines (122 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# test_shadowwatch_integration.py
"""
Shadow Watch Integration Test
Tests that the PyPI package is properly integrated with QuantForge Terminal
"""
import asyncio
import sys
import os
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
async def test_integration():
"""Test Shadow Watch package integration"""
print("=" * 60)
print("Shadow Watch Integration Test")
print("=" * 60)
# Test 1: Import package
print("\n1. Testing package import...")
try:
from shadowwatch import ShadowWatch
print("✅ Package imported successfully")
except Exception as e:
print(f"❌ Failed to import package: {e}")
return
# Test 2: Import compatibility wrapper
print("\n2. Testing compatibility wrapper import...")
try:
from backend.services.shadow_watch_client import (
track_activity,
generate_library_snapshot,
calculate_trust_score
)
print("✅ Compatibility wrapper imported successfully")
except Exception as e:
print(f"❌ Failed to import wrapper: {e}")
return
# Test 3: Initialize Shadow Watch
print("\n3. Testing Shadow Watch initialization...")
try:
from backend.core.config import settings
sw = ShadowWatch(
database_url=settings.DATABASE_URL,
redis_url=settings.REDIS_URL,
license_key=None # Local dev mode
)
print(f"✅ Shadow Watch initialized")
print(f" Database: {settings.DATABASE_URL[:50]}...")
print(f" Redis: {settings.REDIS_URL}")
except Exception as e:
print(f"❌ Failed to initialize: {e}")
import traceback
traceback.print_exc()
return
# Test 4: Initialize database tables
print("\n4. Testing database table creation...")
try:
await sw.init_database()
print("✅ Database tables created/verified")
print(" Tables: shadow_watch_activity_events")
print(" shadow_watch_interests")
print(" shadow_watch_library_versions")
except Exception as e:
print(f"⚠️ Database init warning (may be normal): {e}")
# Test 5: Track activity
print("\n5. Testing activity tracking...")
try:
await sw.track(
user_id=999, # Test user ID
entity_id="AAPL",
action="view",
metadata={"source": "integration_test"}
)
print("✅ Activity tracked successfully")
except Exception as e:
print(f"❌ Failed to track activity: {e}")
import traceback
traceback.print_exc()
# Test 6: Get profile
print("\n6. Testing profile generation...")
try:
profile = await sw.get_profile(user_id=999)
print("✅ Profile generated successfully")
print(f" Total items: {profile.get('total_items', 0)}")
print(f" Fingerprint: {profile.get('fingerprint', 'N/A')[:16]}...")
except Exception as e:
print(f"❌ Failed to get profile: {e}")
import traceback
traceback.print_exc()
# Test 7: Verify login (trust score)
print("\n7. Testing trust score calculation...")
try:
trust_result = await sw.verify_login(
user_id=999,
request_context={
"ip_address": "192.168.1.1",
"user_agent": "Test/1.0",
"library_fingerprint": profile.get('fingerprint', '')
}
)
print("✅ Trust score calculated")
print(f" Score: {trust_result.get('trust_score', 0)}")
print(f" Risk: {trust_result.get('risk_level', 'unknown')}")
print(f" Action: {trust_result.get('action', 'unknown')}")
except Exception as e:
print(f"⚠️ Trust score calculation (expected - needs full implementation): {e}")
# Test 8: Close connection
print("\n8. Testing cleanup...")
try:
await sw.close()
print("✅ Shadow Watch closed cleanly")
except Exception as e:
print(f"⚠️ Close warning: {e}")
print("\n" + "=" * 60)
print("Integration Test Complete!")
print("=" * 60)
print("\n✅ All critical tests passed!")
print("\n📝 Next steps:")
print(" 1. Start the server: uvicorn backend.main:app --reload")
print(" 2. Check startup logs for Shadow Watch initialization")
print(" 3. Make API calls to test activity tracking")
print(" 4. View profile at: GET /shadow-watch/library")
if __name__ == "__main__":
asyncio.run(test_integration())