forked from ChuckBuilds/LEDMatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_web_interface.py
More file actions
144 lines (130 loc) · 4.78 KB
/
test_web_interface.py
File metadata and controls
144 lines (130 loc) · 4.78 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
#!/usr/bin/env python3
"""
Test script for the LED Matrix web interface
This script tests the basic functionality of the web interface
"""
import requests
import json
import time
import sys
def test_web_interface():
"""Test the web interface functionality"""
base_url = "http://localhost:5000"
print("Testing LED Matrix Web Interface...")
print("=" * 50)
# Test 1: Check if the web interface is running
try:
response = requests.get(base_url, timeout=5)
if response.status_code == 200:
print("✓ Web interface is running")
else:
print(f"✗ Web interface returned status code: {response.status_code}")
return False
except requests.exceptions.ConnectionError:
print("✗ Could not connect to web interface. Is it running?")
print(" Start it with: python3 web_interface.py")
return False
except Exception as e:
print(f"✗ Error connecting to web interface: {e}")
return False
# Test 2: Test schedule configuration
print("\nTesting schedule configuration...")
schedule_data = {
'schedule_enabled': 'on',
'start_time': '08:00',
'end_time': '22:00'
}
try:
response = requests.post(f"{base_url}/save_schedule", data=schedule_data, timeout=10)
if response.status_code == 200:
print("✓ Schedule configuration saved successfully")
else:
print(f"✗ Schedule configuration failed: {response.status_code}")
except Exception as e:
print(f"✗ Error saving schedule: {e}")
# Test 3: Test main configuration save
print("\nTesting main configuration save...")
test_config = {
"weather": {
"enabled": True,
"units": "imperial",
"update_interval": 1800
},
"location": {
"city": "Test City",
"state": "Test State"
}
}
try:
response = requests.post(f"{base_url}/save_config", data={
'config_type': 'main',
'config_data': json.dumps(test_config)
}, timeout=10)
if response.status_code == 200:
print("✓ Main configuration saved successfully")
else:
print(f"✗ Main configuration failed: {response.status_code}")
except Exception as e:
print(f"✗ Error saving main config: {e}")
# Test 4: Test secrets configuration save
print("\nTesting secrets configuration save...")
test_secrets = {
"weather": {
"api_key": "test_api_key_123"
},
"youtube": {
"api_key": "test_youtube_key",
"channel_id": "test_channel"
},
"music": {
"SPOTIFY_CLIENT_ID": "test_spotify_id",
"SPOTIFY_CLIENT_SECRET": "test_spotify_secret",
"SPOTIFY_REDIRECT_URI": "http://127.0.0.1:8888/callback"
}
}
try:
response = requests.post(f"{base_url}/save_config", data={
'config_type': 'secrets',
'config_data': json.dumps(test_secrets)
}, timeout=10)
if response.status_code == 200:
print("✓ Secrets configuration saved successfully")
else:
print(f"✗ Secrets configuration failed: {response.status_code}")
except Exception as e:
print(f"✗ Error saving secrets: {e}")
# Test 5: Test action execution
print("\nTesting action execution...")
try:
response = requests.post(f"{base_url}/run_action",
json={'action': 'git_pull'},
timeout=15)
if response.status_code == 200:
result = response.json()
print(f"✓ Action executed: {result.get('status', 'unknown')}")
if result.get('stderr'):
print(f" Note: {result['stderr']}")
else:
print(f"✗ Action execution failed: {response.status_code}")
except Exception as e:
print(f"✗ Error executing action: {e}")
print("\n" + "=" * 50)
print("Web interface testing completed!")
print("\nTo start the web interface:")
print("1. Make sure you're on the Raspberry Pi")
print("2. Run: python3 web_interface.py")
print("3. Open a web browser and go to: http://[PI_IP]:5000")
print("\nFeatures available:")
print("- Schedule configuration")
print("- Display hardware settings")
print("- Sports team configuration")
print("- Weather settings")
print("- Stocks & crypto configuration")
print("- Music settings")
print("- Calendar configuration")
print("- API key management")
print("- System actions (start/stop display, etc.)")
return True
if __name__ == "__main__":
success = test_web_interface()
sys.exit(0 if success else 1)