Files
chat/tests/simple_test.py
Andrew K. Choi 537e7b363f
All checks were successful
continuous-integration/drone/push Build is passing
main commit
2025-10-16 16:30:25 +09:00

66 lines
2.5 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 python
import json
import sys
import requests
import traceback
from datetime import date
# API Gateway endpoint
BASE_URL = "http://localhost:8004"
def main():
try:
print("Начинаем тест мобильного эндпоинта...")
# Проверка работоспособности сервиса
print("Проверяем работоспособность сервиса...")
health_response = requests.get(f"{BASE_URL}/health")
print(f"Ответ о статусе: {health_response.status_code}")
print(f"Тело ответа: {health_response.text}")
# Данные в формате мобильного приложения
mobile_data = {
"date": date.today().isoformat(),
"type": "MENSTRUATION",
"flow_intensity": 3, # средний (1-5)
"symptoms": ["CRAMPS", "HEADACHE"], # массив строк
"mood": "NORMAL",
"notes": "Тестовая запись из мобильного приложения"
}
print(f"Отправляемые данные: {json.dumps(mobile_data, indent=2)}")
# Отправляем запрос к тестовому эндпоинту
print(f"Отправляем запрос на {BASE_URL}/debug/mobile-entry")
response = requests.post(
f"{BASE_URL}/debug/mobile-entry",
json=mobile_data
)
print(f"Статус ответа: {response.status_code}")
print(f"Заголовки ответа: {response.headers}")
try:
response_json = response.json()
print(f"Тело ответа: {json.dumps(response_json, indent=2)}")
except json.JSONDecodeError:
print(f"Ответ не является JSON: {response.text}")
if response.status_code >= 200 and response.status_code < 300:
print("Тест успешно завершен!")
else:
print("Тест завершился с ошибкой.")
sys.exit(1)
except requests.exceptions.ConnectionError:
print(f"Ошибка подключения к {BASE_URL}. Убедитесь, что сервис запущен.")
traceback.print_exc()
sys.exit(1)
except Exception as e:
print(f"Неожиданная ошибка: {e}")
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()