All checks were successful
continuous-integration/drone/push Build is passing
112 lines
5.3 KiB
Python
Executable File
112 lines
5.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
import requests
|
||
import json
|
||
import sys
|
||
|
||
def test_mobile_calendar_entry_creation():
|
||
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIyOSIsImVtYWlsIjoidGVzdDJAZXhhbXBsZS5jb20iLCJleHAiOjE3NTg4NjQwMzV9.Ap4ZD5EtwhLXRtm6KjuFvXMlk6XA-3HtMbaGEu9jX6M"
|
||
|
||
headers = {
|
||
"Content-Type": "application/json",
|
||
"Authorization": f"Bearer {token}"
|
||
}
|
||
|
||
# Используем правильный порт для упрощенного сервиса
|
||
base_url = "http://localhost:8888"
|
||
|
||
# Тестовые данные для мобильного приложения - нужно преобразовать в стандартный формат,
|
||
# так как в упрощенном сервисе нет поддержки мобильного формата
|
||
# Преобразуем формат с "date" -> "entry_date", "type" -> "entry_type" и т.д.
|
||
mobile_data = {
|
||
"entry_date": "2025-09-26",
|
||
"entry_type": "period", # преобразуем MENSTRUATION в period
|
||
"flow_intensity": "heavy", # преобразуем 5 в heavy
|
||
"mood": "happy", # преобразуем HAPPY в happy
|
||
"symptoms": "fatigue", # преобразуем массив в строку
|
||
"notes": "Тестовая запись из мобильного приложения",
|
||
"period_symptoms": "",
|
||
"energy_level": 3,
|
||
"sleep_hours": 8,
|
||
"medications": ""
|
||
}
|
||
|
||
# Тестируем эндпоинт /api/v1/calendar/entries
|
||
print("\n1. Тестирование /api/v1/calendar/entries (стандартный формат)")
|
||
url_mobile = f"{base_url}/api/v1/calendar/entries"
|
||
try:
|
||
response = requests.post(url_mobile, headers=headers, json=mobile_data)
|
||
print(f"Статус ответа: {response.status_code}")
|
||
print(f"Текст ответа: {response.text}")
|
||
|
||
if response.status_code == 201:
|
||
print("✅ Тест успешно пройден! Запись календаря создана через /api/v1/calendar/entry")
|
||
mobile_success = True
|
||
else:
|
||
print(f"❌ Тест не пройден. Код ответа: {response.status_code}")
|
||
mobile_success = False
|
||
except Exception as e:
|
||
print(f"❌ Ошибка при выполнении запроса: {str(e)}")
|
||
mobile_success = False
|
||
|
||
# Тестируем с другими данными в стандартном формате
|
||
print("\n2. Тестирование /api/v1/calendar/entries с другими данными")
|
||
standard_data = {
|
||
"entry_date": "2025-09-30",
|
||
"entry_type": "period",
|
||
"flow_intensity": "medium",
|
||
"notes": "Тестовая запись в стандартном формате",
|
||
"period_symptoms": "",
|
||
"energy_level": 2,
|
||
"sleep_hours": 7,
|
||
"medications": "",
|
||
"symptoms": "headache"
|
||
}
|
||
|
||
url_standard = f"{base_url}/api/v1/calendar/entries"
|
||
try:
|
||
response = requests.post(url_standard, headers=headers, json=standard_data)
|
||
print(f"Статус ответа: {response.status_code}")
|
||
print(f"Текст ответа: {response.text}")
|
||
|
||
if response.status_code == 201:
|
||
print("✅ Тест успешно пройден! Запись календаря создана через /api/v1/entries")
|
||
standard_success = True
|
||
else:
|
||
print(f"❌ Тест не пройден. Код ответа: {response.status_code}")
|
||
standard_success = False
|
||
except Exception as e:
|
||
print(f"❌ Ошибка при выполнении запроса: {str(e)}")
|
||
standard_success = False
|
||
|
||
# Проверяем список записей
|
||
print("\n3. Тестирование GET /api/v1/calendar/entries")
|
||
url_entry = f"{base_url}/api/v1/calendar/entries"
|
||
try:
|
||
response = requests.get(url_entry, headers=headers)
|
||
print(f"Статус ответа: {response.status_code}")
|
||
|
||
if response.status_code == 200:
|
||
entries = response.json()
|
||
print(f"Количество записей: {len(entries)}")
|
||
for i, entry in enumerate(entries):
|
||
print(f"Запись {i+1}: ID={entry['id']}, Дата={entry['entry_date']}, Тип={entry['entry_type']}")
|
||
print("✅ Тест успешно пройден! Получен список записей календаря")
|
||
entry_success = True
|
||
else:
|
||
print(f"❌ Тест не пройден. Код ответа: {response.status_code}")
|
||
print(f"Текст ответа: {response.text}")
|
||
entry_success = False
|
||
except Exception as e:
|
||
print(f"❌ Ошибка при выполнении запроса: {str(e)}")
|
||
entry_success = False
|
||
|
||
# Суммарный результат всех тестов
|
||
if mobile_success and standard_success and entry_success:
|
||
print("\n✅ Все тесты успешно пройдены!")
|
||
return 0
|
||
else:
|
||
print("\n❌ Некоторые тесты не пройдены.")
|
||
return 1
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(test_mobile_calendar_entry_creation()) |