-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_system.py
More file actions
203 lines (167 loc) Β· 5.38 KB
/
Copy pathtest_system.py
File metadata and controls
203 lines (167 loc) Β· 5.38 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
#!/usr/bin/env python3
"""System test script - Verify all components work."""
import sys
import os
from pathlib import Path
def test_imports():
"""Test that all dependencies can be imported."""
print("π Testing imports...")
try:
import playwright
print(" β
playwright")
except ImportError as e:
print(f" β playwright: {e}")
return False
try:
import bs4
print(" β
beautifulsoup4")
except ImportError as e:
print(f" β beautifulsoup4: {e}")
return False
try:
from openai import OpenAI
print(" β
openai")
except ImportError as e:
print(f" β openai: {e}")
return False
try:
import fastapi
print(" β
fastapi")
except ImportError as e:
print(f" β fastapi: {e}")
return False
try:
import dotenv
print(" β
dotenv")
except ImportError as e:
print(f" β dotenv: {e}")
return False
return True
def test_env():
"""Test that .env is configured."""
print("\nπ Testing environment...")
if not Path(".env").exists():
print(" β .env file not found")
print(" β Copy .env.example to .env")
return False
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("NVIDIA_API_KEY")
if not api_key:
print(" β NVIDIA_API_KEY not set in .env")
return False
if api_key.startswith("nvapi-"):
print(f" β
NVIDIA_API_KEY configured")
else:
print(f" β οΈ NVIDIA_API_KEY may be invalid (should start with 'nvapi-')")
return True
def test_database():
"""Test that database can be initialized."""
print("\nπ Testing database...")
try:
from db.database import init_db, exec_query
init_db()
print(" β
Database initialized")
except Exception as e:
print(f" β Database init failed: {e}")
return False
# Check tables exist
try:
tables_result = exec_query(
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'",
fetch=True
)
tables = [row['table_name'] for row in tables_result]
required = ["jobs", "proposals", "feed_log"]
for table in required:
if table in tables:
print(f" β
Table '{table}' exists")
else:
print(f" β Table '{table}' missing")
return False
except Exception as e:
print(f" β Database check failed: {e}")
return False
return True
def test_api():
"""Test that API can start."""
print("\nπ Testing API startup...")
try:
from main import app
print(" β
FastAPI app loaded")
except Exception as e:
print(f" β API load failed: {e}")
return False
# Test health endpoint
try:
from fastapi.testclient import TestClient
client = TestClient(app)
response = client.get("/health")
if response.status_code == 200:
print(" β
Health endpoint works")
else:
print(f" β Health endpoint returned {response.status_code}")
return False
except Exception as e:
print(f" β API test failed: {e}")
return False
return True
def test_ai_api():
"""Test AI API connection (NVIDIA / Kimi)."""
print("\nπ Testing AI API...")
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("NVIDIA_API_KEY")
if not api_key:
print(" β οΈ NVIDIA_API_KEY not set, skipping")
return True
try:
from openai import OpenAI
import config
client = OpenAI(api_key=api_key, base_url=config.AI_BASE_URL)
response = client.chat.completions.create(
model=config.AI_MODEL,
max_tokens=50,
messages=[
{"role": "user", "content": "Say 'OK' in one word"}
]
)
print(" β
AI API connection works")
return True
except Exception as e:
print(f" β AI API failed: {e}")
print(" β Check your API key and account credits")
return False
def main():
"""Run all tests."""
print("=" * 60)
print("π§ͺ UPWORK AUTO-APPLY SYSTEM TEST")
print("=" * 60)
results = []
results.append(("Imports", test_imports()))
results.append(("Environment", test_env()))
results.append(("Database", test_database()))
results.append(("API", test_api()))
results.append(("AI API", test_ai_api()))
print("\n" + "=" * 60)
print("π TEST SUMMARY")
print("=" * 60)
all_passed = True
for name, passed in results:
status = "β
PASS" if passed else "β FAIL"
print(f"{name:<20} {status}")
if not passed:
all_passed = False
print("=" * 60)
if all_passed:
print("\n⨠All tests passed! Ready to run.")
print("\nNext steps:")
print("1. python main.py # Start the backend")
print("2. open http://localhost:8000/dashboard/index.html")
print("3. Click 'Run Cycle' to fetch and generate proposals")
return 0
else:
print("\nβ Some tests failed. Check errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())