Files
python_parser/test_api_direct.py
2025-09-01 13:58:42 +03:00

79 lines
2.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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()