All checks were successful
continuous-integration/drone/push Build is passing
121 lines
4.7 KiB
Python
Executable File
121 lines
4.7 KiB
Python
Executable File
#!/usr/bin/env python
|
||
|
||
import json
|
||
import requests
|
||
from datetime import date
|
||
|
||
# Используем сохраненный токен авторизации
|
||
with open('auth_token.txt', 'r') as f:
|
||
TOKEN = f.read().strip()
|
||
|
||
# Базовый URL для тестирования
|
||
BASE_URL = "http://localhost:8004"
|
||
HEADERS = {
|
||
"Content-Type": "application/json",
|
||
"Authorization": f"Bearer {TOKEN}"
|
||
}
|
||
|
||
# Функция для тестирования мобильного эндпоинта
|
||
def test_mobile_endpoint():
|
||
url = f"{BASE_URL}/api/v1/calendar/entries/mobile"
|
||
|
||
# Данные для мобильного запроса
|
||
data = {
|
||
"date": date.today().isoformat(),
|
||
"type": "MENSTRUATION",
|
||
"flow_intensity": 3,
|
||
"symptoms": ["CRAMPS", "HEADACHE"],
|
||
"mood": "NORMAL",
|
||
"notes": "Тест мобильного API"
|
||
}
|
||
|
||
print("\n1. Тестирование создания записи через мобильный API...")
|
||
print(f"POST {url}")
|
||
print(f"Данные: {json.dumps(data, ensure_ascii=False)}")
|
||
|
||
try:
|
||
response = requests.post(url, json=data, headers=HEADERS)
|
||
|
||
if response.status_code == 201:
|
||
print(f"✅ Успешно! Статус: {response.status_code}")
|
||
print(f"Ответ: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
|
||
|
||
# Теперь проверим, что мы можем получить запись
|
||
entry_id = response.json().get("id")
|
||
return entry_id
|
||
else:
|
||
print(f"❌ Ошибка! Статус: {response.status_code}")
|
||
print(f"Ответ: {response.text}")
|
||
return None
|
||
except Exception as e:
|
||
print(f"❌ Исключение: {str(e)}")
|
||
return None
|
||
|
||
# Функция для проверки получения всех записей
|
||
def test_get_entries(entry_id=None):
|
||
url = f"{BASE_URL}/api/v1/calendar/entries"
|
||
|
||
print("\n2. Проверка получения записей календаря...")
|
||
print(f"GET {url}")
|
||
|
||
try:
|
||
response = requests.get(url, headers=HEADERS)
|
||
|
||
if response.status_code == 200:
|
||
print(f"✅ Успешно! Статус: {response.status_code}")
|
||
entries = response.json()
|
||
print(f"Получено записей: {len(entries)}")
|
||
|
||
# Если у нас есть ID записи, которую мы создали ранее, проверим ее наличие
|
||
if entry_id:
|
||
found = False
|
||
for entry in entries:
|
||
if entry.get("id") == entry_id:
|
||
found = True
|
||
print(f"✅ Созданная запись найдена в списке (ID: {entry_id})")
|
||
break
|
||
|
||
if not found:
|
||
print(f"❌ Созданная запись не найдена в списке (ID: {entry_id})")
|
||
else:
|
||
print(f"❌ Ошибка! Статус: {response.status_code}")
|
||
print(f"Ответ: {response.text}")
|
||
except Exception as e:
|
||
print(f"❌ Исключение: {str(e)}")
|
||
|
||
# Тестирование отладочного эндпоинта (без аутентификации)
|
||
def test_debug_endpoint():
|
||
url = f"{BASE_URL}/debug/mobile-entry"
|
||
|
||
# Данные для мобильного запроса
|
||
data = {
|
||
"date": date.today().isoformat(),
|
||
"type": "MENSTRUATION",
|
||
"flow_intensity": 3,
|
||
"symptoms": ["CRAMPS", "HEADACHE"],
|
||
"mood": "NORMAL",
|
||
"notes": "Тест отладочного API"
|
||
}
|
||
|
||
print("\n3. Тестирование отладочного эндпоинта...")
|
||
print(f"POST {url}")
|
||
print(f"Данные: {json.dumps(data, ensure_ascii=False)}")
|
||
|
||
try:
|
||
response = requests.post(url, json=data)
|
||
|
||
if response.status_code == 200:
|
||
print(f"✅ Успешно! Статус: {response.status_code}")
|
||
print(f"Ответ: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
|
||
else:
|
||
print(f"❌ Ошибка! Статус: {response.status_code}")
|
||
print(f"Ответ: {response.text}")
|
||
except Exception as e:
|
||
print(f"❌ Исключение: {str(e)}")
|
||
|
||
if __name__ == "__main__":
|
||
print("=== Тестирование мобильного API календарного сервиса ===")
|
||
entry_id = test_mobile_endpoint()
|
||
test_get_entries(entry_id)
|
||
test_debug_endpoint()
|
||
print("\nТестирование завершено!") |