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

69 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

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
"""
Тестирование загрузки Excel файла
"""
import requests
import os
def test_file_upload():
"""Тестирование загрузки файла"""
base_url = "http://localhost:8000"
filename = "test_file.xlsx"
print("🧪 ТЕСТ ЗАГРУЗКИ ФАЙЛА")
print("=" * 40)
# Проверяем, что файл существует
if not os.path.exists(filename):
print(f"❌ Файл {filename} не найден")
return False
print(f"📁 Файл найден: {filename}")
print(f"📏 Размер: {os.path.getsize(filename)} байт")
# Тестируем загрузку в разные парсеры
parsers = [
("svodka_ca", "/svodka_ca/upload", "file"),
("monitoring_fuel", "/monitoring_fuel/upload-zip", "zip_file"),
("svodka_pm", "/svodka_pm/upload-zip", "zip_file")
]
for parser_name, endpoint, file_param in parsers:
print(f"\n🔍 Тестирую {parser_name}...")
try:
# Читаем файл
with open(filename, 'rb') as f:
file_data = f.read()
# Определяем content type
if filename.endswith('.xlsx'):
content_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
else:
content_type = "application/octet-stream"
# Загружаем файл с правильным параметром
files = {file_param: (filename, file_data, content_type)}
response = requests.post(f"{base_url}{endpoint}", files=files)
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🎯 Тестирование завершено!")
return True
if __name__ == "__main__":
test_file_upload()