ShopTRAINING/test/simple_test.py
2025-07-02 11:05:23 +08:00

38 lines
970 B
Python

#!/usr/bin/env python3
"""
简单的API测试
"""
import requests
def test_simple():
"""测试简单的API端点"""
endpoints = [
"/api/products",
"/api/stores"
]
for endpoint in endpoints:
try:
url = f"http://localhost:5000{endpoint}"
print(f"测试: {endpoint}")
response = requests.get(url, timeout=3)
print(f"状态码: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f"状态: {data.get('status', 'unknown')}")
print(f"数据数量: {len(data.get('data', []))}")
print("✓ 成功")
else:
print(f"✗ 失败: {response.text[:100]}")
except Exception as e:
print(f"✗ 错误: {e}")
print("-" * 30)
if __name__ == "__main__":
test_simple()