cosmo/backend/test_nasa_body_param.py

43 lines
1.2 KiB
Python

"""
Test NASA SBDB API body parameter format
"""
import asyncio
import httpx
async def test_body_param():
"""Test different body parameter formats"""
test_cases = [
("Earth (name)", "Earth"),
("399 (Horizons ID)", "399"),
("Mars (name)", "Mars"),
("499 (Mars Horizons ID)", "499"),
]
for name, body_value in test_cases:
params = {
"date-min": "2025-12-15",
"date-max": "2025-12-16",
"body": body_value,
"limit": "1"
}
try:
async with httpx.AsyncClient(timeout=10.0, proxies={}) as client:
response = await client.get(
"https://ssd-api.jpl.nasa.gov/cad.api",
params=params
)
if response.status_code == 200:
data = response.json()
count = data.get("count", 0)
print(f"{name:30} -> 返回 {count:3} 个结果 ✓")
else:
print(f"{name:30} -> HTTP {response.status_code}")
except Exception as e:
print(f"{name:30} -> 错误: {e}")
if __name__ == "__main__":
asyncio.run(test_body_param())