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

96 lines
3.8 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.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Тестирование полного workflow с сводкой СА
"""
import requests
import os
import time
def test_ca_workflow():
"""Тестирование полного workflow с сводкой СА"""
base_url = "http://localhost:8000"
test_file = "python_parser/data/svodka_ca.xlsx"
print("🧪 ТЕСТ ПОЛНОГО WORKFLOW СВОДКИ СА")
print("=" * 50)
# Проверяем, что файл существует
if not os.path.exists(test_file):
print(f"❌ Файл {test_file} не найден")
return False
print(f"📁 Тестовый файл найден: {test_file}")
print(f"📏 Размер: {os.path.getsize(test_file)} байт")
# Шаг 1: Загружаем файл
print("\n1⃣ Загружаю файл сводки СА...")
try:
with open(test_file, 'rb') as f:
file_data = f.read()
files = {"file": ("svodka_ca.xlsx", file_data, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")}
response = requests.post(f"{base_url}/svodka_ca/upload", files=files)
print(f"📤 Результат загрузки: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"✅ Файл загружен: {result}")
object_id = result.get('object_id', 'nin_excel_data_svodka_ca')
else:
print(f"❌ Ошибка загрузки: {response.status_code}")
try:
error_detail = response.json()
print(f"📋 Детали ошибки: {error_detail}")
except:
print(f"📋 Текст ошибки: {response.text}")
return False
except Exception as e:
print(f"❌ Ошибка загрузки: {e}")
return False
# Шаг 2: Получаем данные через геттер
print("\n2⃣ Получаю данные через геттер...")
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"✅ Данные получены успешно!")
print(f"📊 Размер ответа: {len(str(result))} символов")
# Показываем структуру данных
if isinstance(result, dict):
print(f"🔍 Структура данных:")
for key, value in result.items():
if isinstance(value, dict):
print(f" {key}: {len(value)} элементов")
else:
print(f" {key}: {type(value).__name__}")
else:
print(f"❌ Ошибка получения данных: {response.status_code}")
try:
error_detail = response.json()
print(f"📋 Детали ошибки: {error_detail}")
except:
print(f"📋 Текст ошибки: {response.text}")
return False
except Exception as e:
print(f"❌ Ошибка получения данных: {e}")
return False
print("\n🎯 Тестирование завершено успешно!")
return True
if __name__ == "__main__":
test_ca_workflow()