Repository navigation
Expand file tree
/
Copy pathtest_setup.py
More file actions
163 lines (144 loc) · 4.87 KB
/
Copy pathtest_setup.py
File metadata and controls
163 lines (144 loc) · 4.87 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
#!/usr/bin/env python3
"""
Test script to verify WordPress Local Development Environment setup
"""
import sys
import os
import subprocess
from pathlib import Path
def test_python_version():
"""Test if Python version is 3.8 or higher"""
version = sys.version_info
if version.major >= 3 and version.minor >= 8:
print("✅ Python version:", f"{version.major}.{version.minor}.{version.micro}")
return True
else:
print("❌ Python 3.8+ required, found:", f"{version.major}.{version.minor}.{version.micro}")
return False
def test_required_modules():
"""Test if required Python modules can be imported"""
modules = [
'flask',
'cryptography',
'yaml',
'pathlib',
'subprocess',
'json',
'platform'
]
failed = []
for module in modules:
try:
__import__(module)
print(f"✅ Module {module} - OK")
except ImportError:
print(f"❌ Module {module} - MISSING")
failed.append(module)
return len(failed) == 0
def test_docker():
"""Test if Docker is installed and running"""
try:
result = subprocess.run(['docker', '--version'], capture_output=True, text=True)
if result.returncode == 0:
print(f"✅ Docker installed: {result.stdout.strip()}")
# Test if Docker is running
result = subprocess.run(['docker', 'info'], capture_output=True, text=True)
if result.returncode == 0:
print("✅ Docker is running")
return True
else:
print("❌ Docker is not running")
return False
else:
print("❌ Docker not found")
return False
except FileNotFoundError:
print("❌ Docker not installed")
return False
def test_docker_compose():
"""Test if Docker Compose is installed"""
try:
result = subprocess.run(['docker-compose', '--version'], capture_output=True, text=True)
if result.returncode == 0:
print(f"✅ Docker Compose installed: {result.stdout.strip()}")
return True
else:
print("❌ Docker Compose not found")
return False
except FileNotFoundError:
print("❌ Docker Compose not installed")
return False
def test_file_structure():
"""Test if required files and directories exist"""
required_files = [
'app.py',
'requirements.txt',
'templates/index.html',
'static/css/style.css',
'static/js/app.js',
'utils/__init__.py',
'utils/project_manager.py',
'utils/ssl_generator.py',
'utils/hosts_manager.py',
'start.sh',
'start.bat'
]
missing = []
for file_path in required_files:
if Path(file_path).exists():
print(f"✅ {file_path} - OK")
else:
print(f"❌ {file_path} - MISSING")
missing.append(file_path)
return len(missing) == 0
def test_permissions():
"""Test if scripts have correct permissions"""
scripts = ['start.sh']
for script in scripts:
if Path(script).exists():
if os.access(script, os.X_OK):
print(f"✅ {script} is executable")
else:
print(f"❌ {script} is not executable (run: chmod +x {script})")
else:
print(f"❌ {script} not found")
def main():
"""Run all tests"""
print("🧪 WordPress Local Development Environment - Setup Test")
print("=" * 60)
tests = [
("Python Version", test_python_version),
("Required Modules", test_required_modules),
("Docker", test_docker),
("Docker Compose", test_docker_compose),
("File Structure", test_file_structure),
]
results = []
for test_name, test_func in tests:
print(f"\n📋 Testing {test_name}...")
try:
result = test_func()
results.append(result)
except Exception as e:
print(f"❌ Error in {test_name}: {str(e)}")
results.append(False)
# Additional permission test (non-blocking)
print(f"\n📋 Testing Script Permissions...")
test_permissions()
print("\n" + "=" * 60)
passed = sum(results)
total = len(results)
if passed == total:
print("🎉 All tests passed! Your setup is ready.")
print("\nTo start the application:")
print(" ./start.sh (macOS/Linux)")
print(" start.bat (Windows)")
return True
else:
print(f"⚠️ {passed}/{total} tests passed. Please fix the issues above.")
if not test_required_modules():
print("\n💡 To install missing modules:")
print(" pip install -r requirements.txt")
return False
if __name__ == "__main__":
sys.exit(0 if main() else 1)