-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend_test.py
More file actions
213 lines (180 loc) · 8.83 KB
/
Copy pathbackend_test.py
File metadata and controls
213 lines (180 loc) · 8.83 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
import requests
import unittest
import sys
from datetime import datetime
class MeteorShowerAPITester:
def __init__(self, base_url="https://97de1fab-1594-4799-99f3-38c4b6bc2050.preview.emergentagent.com"):
self.base_url = base_url
self.tests_run = 0
self.tests_passed = 0
def run_test(self, name, method, endpoint, expected_status, data=None):
"""Run a single API test"""
url = f"{self.base_url}{endpoint}"
headers = {'Content-Type': 'application/json'}
self.tests_run += 1
print(f"\n🔍 Testing {name}...")
try:
if method == 'GET':
response = requests.get(url, headers=headers)
elif method == 'POST':
response = requests.post(url, json=data, headers=headers)
success = response.status_code == expected_status
if success:
self.tests_passed += 1
print(f"✅ Passed - Status: {response.status_code}")
return success, response.json() if response.status_code != 204 else {}
else:
print(f"❌ Failed - Expected {expected_status}, got {response.status_code}")
print(f"Response: {response.text}")
return False, {}
except Exception as e:
print(f"❌ Failed - Error: {str(e)}")
return False, {}
def test_health_check(self):
"""Test the health check endpoint"""
success, response = self.run_test(
"Health Check",
"GET",
"/api/health",
200
)
if success:
print(f"Health check response: {response}")
return success
def test_meteor_showers(self, latitude, longitude):
"""Test the meteor showers endpoint with location data"""
success, response = self.run_test(
"Meteor Showers",
"POST",
"/api/meteor-showers",
200,
data={"latitude": latitude, "longitude": longitude}
)
if success:
print(f"Location name: {response.get('user_location', {}).get('location_name', 'Unknown')}")
print(f"Hemisphere: {response.get('user_location', {}).get('hemisphere', 'Unknown')}")
print(f"Active showers: {len(response.get('active_showers', []))}")
print(f"Upcoming showers: {len(response.get('upcoming_showers', []))}")
# Check for enhanced meteor shower information
if response.get('active_showers') or response.get('upcoming_showers'):
showers = response.get('active_showers', []) + response.get('upcoming_showers', [])
if showers:
shower = showers[0]
print("\nEnhanced Meteor Shower Information:")
print(f"Radiant rise time: {shower.get('radiant_rise_time', 'N/A')}")
print(f"Radiant zenith time: {shower.get('radiant_zenith_time', 'N/A')}")
print(f"Radiant set time: {shower.get('radiant_set_time', 'N/A')}")
print(f"Moon phase: {shower.get('moon_phase', 'N/A')}")
print(f"Moon interference: {shower.get('moon_interference', 'N/A')}")
print(f"Visibility score: {shower.get('visibility_score', 'N/A')}")
# Test star map data
star_map = shower.get('star_map')
if star_map:
print("\nStar Map Data:")
print(f"Target constellation: {star_map.get('target_constellation', {}).get('name', 'N/A')}")
print(f"Number of nearby constellations: {len(star_map.get('nearby_constellations', []))}")
print(f"Sky position - Altitude: {star_map.get('target_constellation', {}).get('sky_position', {}).get('altitude', 'N/A')}")
print(f"Sky position - Azimuth: {star_map.get('target_constellation', {}).get('sky_position', {}).get('azimuth', 'N/A')}")
# Check if target constellation has stars
target_stars = star_map.get('target_constellation', {}).get('stars', [])
print(f"Target constellation stars: {len(target_stars)}")
if target_stars:
print(f"Sample star: {target_stars[0].get('name')} (Magnitude: {target_stars[0].get('mag')})")
# Check if nearby constellations have stars
nearby_constellations = star_map.get('nearby_constellations', [])
if nearby_constellations:
nearby_constellation = nearby_constellations[0]
print(f"Nearby constellation: {nearby_constellation.get('name')}")
nearby_stars = nearby_constellation.get('stars', [])
print(f"Nearby constellation stars: {len(nearby_stars)}")
else:
print("\nNo star map data found!")
return success, response
def test_calendar_data(self, year):
"""Test the calendar data endpoint for a specific year"""
success, response = self.run_test(
f"Calendar Data for {year}",
"GET",
f"/api/calendar/{year}",
200
)
if success:
print(f"Year: {response.get('year')}")
print(f"Total showers: {response.get('total_showers')}")
# Check monthly data structure
monthly_data = response.get('monthly_showers', {})
if monthly_data:
print("\nMonthly data structure:")
for month, showers in monthly_data.items():
print(f"Month {month}: {len(showers)} showers")
# Check a sample shower from a month with data
for month, showers in monthly_data.items():
if showers:
sample_shower = showers[0]
print("\nSample shower data:")
print(f"Name: {sample_shower.get('name')}")
print(f"Peak day: {sample_shower.get('peak_day')}")
print(f"Max rate: {sample_shower.get('max_rate')}")
print(f"Constellation: {sample_shower.get('radiant_constellation')}")
break
return success, response
def test_years_available(self):
"""Test the years available endpoint"""
success, response = self.run_test(
"Years Available",
"GET",
"/api/years-available",
200
)
if success:
print(f"Available years: {response.get('years')}")
print(f"Current year: {response.get('current_year')}")
return success, response
def main():
# Setup
tester = MeteorShowerAPITester()
# Test locations
test_locations = [
{"name": "New York", "latitude": 40.7128, "longitude": -74.0060},
{"name": "Sydney", "latitude": -33.8688, "longitude": 151.2093}
]
# Run tests
print("=" * 50)
print("METEOR SHOWER APP API TESTING")
print("=" * 50)
# 1. Health check
health_check_success = tester.test_health_check()
if not health_check_success:
print("❌ Health check failed, stopping tests")
return 1
# 2. Years available
years_success, years_data = tester.test_years_available()
if not years_success:
print("❌ Years available check failed")
# 3. Test with different locations
for location in test_locations:
print(f"\n\n{'=' * 30}")
print(f"Testing with location: {location['name']}")
print(f"{'=' * 30}")
meteor_success, meteor_data = tester.test_meteor_showers(
location["latitude"],
location["longitude"]
)
if not meteor_success:
print(f"❌ Meteor shower data failed for {location['name']}")
# 4. Test calendar data for available years
if years_success and years_data.get('years'):
for year in years_data.get('years')[:2]: # Test first two years only
print(f"\n\n{'=' * 30}")
print(f"Testing calendar data for year: {year}")
print(f"{'=' * 30}")
calendar_success, _ = tester.test_calendar_data(year)
if not calendar_success:
print(f"❌ Calendar data failed for year {year}")
# Print results
print(f"\n\n{'=' * 50}")
print(f"📊 Tests passed: {tester.tests_passed}/{tester.tests_run}")
print(f"{'=' * 50}")
return 0 if tester.tests_passed == tester.tests_run else 1
if __name__ == "__main__":
sys.exit(main())