-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_project.py
More file actions
245 lines (199 loc) · 6.52 KB
/
test_project.py
File metadata and controls
245 lines (199 loc) · 6.52 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
242
243
244
245
#!/usr/bin/env python3
"""
EV Spot Project Test Script
This script tests all major components of the EV Spot project
"""
import os
import sys
import subprocess
import requests
import json
from pathlib import Path
def test_python_imports():
"""Test if all required Python packages can be imported"""
print("🔍 Testing Python imports...")
required_packages = [
'django',
'rest_framework',
'corsheaders',
'PIL',
'django_filters'
]
for package in required_packages:
try:
__import__(package)
print(f"✅ {package}")
except ImportError as e:
print(f"❌ {package}: {e}")
return False
return True
def test_django_setup():
"""Test Django setup"""
print("\n🔍 Testing Django setup...")
try:
import django
from django.conf import settings
from django.core.management import execute_from_command_line
# Set up Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'evspot.settings')
django.setup()
print("✅ Django setup successful")
return True
except Exception as e:
print(f"❌ Django setup failed: {e}")
return False
def test_database_models():
"""Test database models"""
print("\n🔍 Testing database models...")
try:
from users.models import CustomUser
from stations.models import ChargingStation, ChargingSession, Review, FavoriteStation
print("✅ All models imported successfully")
return True
except Exception as e:
print(f"❌ Model import failed: {e}")
return False
def test_api_endpoints():
"""Test API endpoints"""
print("\n🔍 Testing API endpoints...")
base_url = "http://127.0.0.1:8000"
endpoints = [
"/api/stations/",
"/api/users/register/",
"/api/users/login/",
]
for endpoint in endpoints:
try:
response = requests.get(f"{base_url}{endpoint}", timeout=5)
print(f"✅ {endpoint}: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"⚠️ {endpoint}: {e} (server might not be running)")
return True
def test_static_files():
"""Test if static files exist"""
print("\n🔍 Testing static files...")
static_files = [
"static/css/style.css",
"static/js/main.js",
"static/images/hero-ev.jpg",
"static/images/about-ev.jpg"
]
for file_path in static_files:
if os.path.exists(file_path):
print(f"✅ {file_path}")
else:
print(f"❌ {file_path} (missing)")
return True
def test_templates():
"""Test if templates exist"""
print("\n🔍 Testing templates...")
template_files = [
"templates/base.html",
"templates/index.html"
]
for file_path in template_files:
if os.path.exists(file_path):
print(f"✅ {file_path}")
else:
print(f"❌ {file_path} (missing)")
return True
def test_migrations():
"""Test if migrations exist"""
print("\n🔍 Testing migrations...")
migration_dirs = [
"users/migrations",
"stations/migrations"
]
for migration_dir in migration_dirs:
if os.path.exists(migration_dir):
migration_files = [f for f in os.listdir(migration_dir) if f.endswith('.py') and f != '__init__.py']
if migration_files:
print(f"✅ {migration_dir}: {len(migration_files)} migration(s)")
else:
print(f"⚠️ {migration_dir}: No migrations found")
else:
print(f"❌ {migration_dir} (missing)")
return True
def test_directories():
"""Test if required directories exist"""
print("\n🔍 Testing directories...")
required_dirs = [
"media",
"media/profile_pics",
"media/station_images",
"staticfiles",
"logs"
]
for directory in required_dirs:
if os.path.exists(directory):
print(f"✅ {directory}")
else:
print(f"❌ {directory} (missing)")
return True
def test_requirements():
"""Test requirements.txt"""
print("\n🔍 Testing requirements.txt...")
if os.path.exists("requirements.txt"):
with open("requirements.txt", "r") as f:
requirements = f.read()
if requirements.strip():
print("✅ requirements.txt exists and has content")
return True
else:
print("❌ requirements.txt is empty")
return False
else:
print("❌ requirements.txt missing")
return False
def run_django_checks():
"""Run Django system checks"""
print("\n🔍 Running Django system checks...")
try:
result = subprocess.run(
["python", "manage.py", "check"],
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
print("✅ Django system checks passed")
return True
else:
print(f"❌ Django system checks failed: {result.stderr}")
return False
except Exception as e:
print(f"⚠️ Could not run Django checks: {e}")
return False
def main():
"""Main test function"""
print("🧪 EV Spot Project Test Suite")
print("=" * 50)
tests = [
("Python Imports", test_python_imports),
("Django Setup", test_django_setup),
("Database Models", test_database_models),
("Static Files", test_static_files),
("Templates", test_templates),
("Migrations", test_migrations),
("Directories", test_directories),
("Requirements", test_requirements),
("Django Checks", run_django_checks),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
try:
if test_func():
passed += 1
except Exception as e:
print(f"❌ {test_name} failed with exception: {e}")
print("\n" + "=" * 50)
print(f"📊 Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! Your project is ready to run.")
else:
print("⚠️ Some tests failed. Please check the issues above.")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)