79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Прямое тестирование API эндпоинтов
|
||
"""
|
||
|
||
import requests
|
||
import json
|
||
|
||
def test_api_endpoints():
|
||
"""Тестирование API эндпоинтов"""
|
||
base_url = "http://localhost:8000"
|
||
|
||
print("🧪 ПРЯМОЕ ТЕСТИРОВАНИЕ API")
|
||
print("=" * 40)
|
||
|
||
# Тест 1: Проверка доступности API
|
||
print("\n1️⃣ Проверка доступности API...")
|
||
try:
|
||
response = requests.get(f"{base_url}/")
|
||
print(f"✅ API доступен: {response.status_code}")
|
||
except Exception as e:
|
||
print(f"❌ Ошибка: {e}")
|
||
return
|
||
|
||
# Тест 2: Тестирование эндпоинта svodka_ca/get_data
|
||
print("\n2️⃣ Тестирование svodka_ca/get_data...")
|
||
try:
|
||
data = {
|
||
"getter": "get_data",
|
||
"modes": ["plan", "fact"],
|
||
"tables": ["ТиП", "Топливо"]
|
||
}
|
||
|
||
response = requests.post(f"{base_url}/svodka_ca/get_data", json=data)
|
||
print(f"📥 Результат: {response.status_code}")
|
||
|
||
if response.status_code == 200:
|
||
result = response.json()
|
||
print(f"✅ Успешно: {result}")
|
||
else:
|
||
try:
|
||
error_detail = response.json()
|
||
print(f"❌ Ошибка: {error_detail}")
|
||
except:
|
||
print(f"❌ Ошибка: {response.text}")
|
||
|
||
except Exception as e:
|
||
print(f"❌ Исключение: {e}")
|
||
|
||
# Тест 3: Тестирование эндпоинта svodka_pm/get_data
|
||
print("\n3️⃣ Тестирование svodka_pm/get_data...")
|
||
try:
|
||
data = {
|
||
"getter": "single_og",
|
||
"id": "SNPZ",
|
||
"codes": [78, 79],
|
||
"columns": ["БП", "ПП"]
|
||
}
|
||
|
||
response = requests.post(f"{base_url}/svodka_pm/get_data", json=data)
|
||
print(f"📥 Результат: {response.status_code}")
|
||
|
||
if response.status_code == 200:
|
||
result = response.json()
|
||
print(f"✅ Успешно: {result}")
|
||
else:
|
||
try:
|
||
error_detail = response.json()
|
||
print(f"❌ Ошибка: {error_detail}")
|
||
except:
|
||
print(f"❌ Ошибка: {response.text}")
|
||
|
||
except Exception as e:
|
||
print(f"❌ Исключение: {e}")
|
||
|
||
print("\n🎯 Тестирование завершено!")
|
||
|
||
if __name__ == "__main__":
|
||
test_api_endpoints() |