-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_setup.py
More file actions
executable file
·241 lines (188 loc) · 6.8 KB
/
test_setup.py
File metadata and controls
executable file
·241 lines (188 loc) · 6.8 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python3
"""
Test Script for dMail SQLite Setup
This script verifies that the SQLite database and all components are working correctly.
"""
import sys
import os
from pathlib import Path
def test_database():
"""Test database connectivity and basic operations."""
print("🧪 Testing database...")
# Add daemon-service to path
daemon_dir = Path("daemon-service")
if not daemon_dir.exists():
print("❌ daemon-service directory not found")
return False
sys.path.insert(0, str(daemon_dir))
try:
from database import db
# Test database initialization
print("✅ Database module imported successfully")
# Test user operations
test_email = "test@example.com"
test_host = "imap.gmail.com"
test_password = "test-password"
# Add test user
success = db.put_user(test_email, test_host, test_password)
if not success:
print("❌ Failed to add test user")
return False
print("✅ Test user added successfully")
# Get test user
users = db.get_users()
found_user = False
for user in users:
if user.get('user') == test_email:
found_user = True
break
if not found_user:
print("❌ Test user not found")
return False
print("✅ Test user retrieved successfully")
# Test metadata operations
test_metadata = {"test_key": "test_value"}
success = db.put_metadata("test_user", test_metadata)
if not success:
print("❌ Failed to add test metadata")
return False
print("✅ Test metadata added successfully")
# Get test metadata
metadata = db.get_metadata("test_user")
if not metadata:
print("❌ Test metadata not found")
return False
print("✅ Test metadata retrieved successfully")
# Test email operations
test_email_data = {
'message_id': 'test-123',
'subject': 'Test Subject',
'to': 'test@example.com',
'from': 'sender@example.com',
'body': 'Test body',
'date': '2024-01-01T00:00:00Z',
'processed': False,
'action': '',
'draft': '',
'account': test_email,
}
success = db.put_email(test_email_data)
if not success:
print("❌ Failed to add test email")
return False
print("✅ Test email added successfully")
# Get test email
email = db.get_email('test-123')
if not email:
print("❌ Test email not found")
return False
print("✅ Test email retrieved successfully")
# Update test email
success = db.update_email('test-123', {'processed': True, 'action': 'tested'})
if not success:
print("❌ Failed to update test email")
return False
print("✅ Test email updated successfully")
# Scan emails
emails = db.scan_emails()
if not emails:
print("❌ No emails found in scan")
return False
print("✅ Email scan working successfully")
# Clean up test data
# (In a real implementation, you might want to add delete methods)
return True
except Exception as e:
print(f"❌ Database test failed: {e}")
return False
def test_config():
"""Test configuration loading."""
print("🧪 Testing configuration...")
# Add daemon-service to path
daemon_dir = Path("daemon-service")
if not daemon_dir.exists():
print("❌ daemon-service directory not found")
return False
sys.path.insert(0, str(daemon_dir))
try:
import config_reader
# Test config values
database_path = getattr(config_reader, 'DATABASE_PATH', None)
if not database_path:
print("❌ DATABASE_PATH not found in config")
return False
print(f"✅ DATABASE_PATH: {database_path}")
lookback_days = getattr(config_reader, 'LOOKBACK_DAYS', None)
if lookback_days is None:
print("❌ LOOKBACK_DAYS not found in config")
return False
print(f"✅ LOOKBACK_DAYS: {lookback_days}")
# Test secrets loading
host = getattr(config_reader, 'HOST', None)
if not host:
print("❌ HOST not found in config")
return False
print(f"✅ HOST: {host}")
return True
except Exception as e:
print(f"❌ Configuration test failed: {e}")
return False
def test_imports():
"""Test that all required modules can be imported."""
print("🧪 Testing imports...")
# Add daemon-service to path
daemon_dir = Path("daemon-service")
if not daemon_dir.exists():
print("❌ daemon-service directory not found")
return False
sys.path.insert(0, str(daemon_dir))
modules_to_test = [
'database',
'config_reader',
'filter_utils',
'ai_processor',
]
for module_name in modules_to_test:
try:
__import__(module_name)
print(f"✅ {module_name} imported successfully")
except ImportError as e:
print(f"❌ Failed to import {module_name}: {e}")
return False
return True
def main():
"""Main test function."""
print("🧪 dMail SQLite Setup Test")
print("==========================")
# Run all tests
tests = [
("Import Test", test_imports),
("Configuration Test", test_config),
("Database Test", test_database),
]
passed = 0
failed = 0
for test_name, test_func in tests:
print(f"\n{test_name}:")
try:
if test_func():
print(f"✅ {test_name} PASSED")
passed += 1
else:
print(f"❌ {test_name} FAILED")
failed += 1
except Exception as e:
print(f"❌ {test_name} FAILED with exception: {e}")
failed += 1
print(f"\n📊 Test Results:")
print(f"✅ Passed: {passed}")
print(f"❌ Failed: {failed}")
if failed == 0:
print("\n🎉 All tests passed! Your dMail setup is working correctly.")
return True
else:
print(f"\n💥 {failed} test(s) failed. Please check the errors above.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)