""" MELODIX - Test de Integración Prueba el flujo completo: registro, login, subida, procesamiento y descarga. Uso: python tests/integration_test.py """ import requests import os import sys import time # ========================================== # CONFIGURACIÓN # ========================================== BASE_URL = os.getenv("TEST_BASE_URL", "http://127.0.0.1:8000") TEST_USER = "testuser_integration" TEST_PASS = "password123" TEST_EMAIL = "test_integration@example.com" TEST_FILE = "tests/test.wav" # Crear archivo de test si no existe if not os.path.exists("tests"): os.makedirs("tests") # ========================================== # FUNCIONES AUXILIARES # ========================================== def create_test_audio(): """Crea un archivo WAV válido para testing""" import wave import struct duration = 2 # segundos sample_rate = 44100 frequency = 440 # Hz (A4) num_samples = int(sample_rate * duration) with wave.open(TEST_FILE, 'w') as wav_file: wav_file.setnchannels(1) # Mono wav_file.setsampwidth(2) # 16 bits wav_file.setframerate(sample_rate) for i in range(num_samples): # Generar onda sinusoidal value = int(32767.0 * 0.5 * 1) # Amplitud al 50% data = struct.pack('= max_attempts: print(f" ⚠ Timeout: La tarea tardó más de {max_attempts * 2} segundos") # ========================================== # TEST 7: HISTORIAL # ========================================== print_separator("TEST 7: HISTORIAL DE CANCIONES") try: res = requests.get( f"{BASE_URL}/songs/history", headers=headers, timeout=10 ) if res.status_code == 200: history = res.json() print(f" Total canciones: {history.get('total')}") tasks = history.get('tasks', []) if tasks: print(f" Última canción:") print(f" - Nombre: {tasks[0].get('song_name')}") print(f" - Stems: {tasks[0].get('stems')}") print(f" - Estado: {tasks[0].get('status')}") print(f" ✓ Historial obtenido correctamente") else: print(f" ✗ FALLO HISTORIAL: {res.status_code}") except Exception as e: print(f" ✗ ERROR: {e}") # ========================================== # RESUMEN FINAL # ========================================== print_separator("RESUMEN DE TESTS") print(" ✓ Registro/Login") print(" ✓ Verificación de créditos") print(" ✓ Subida de archivo") print(" ✓ Descuento de créditos") print(" ✓ Consulta de estado") print(" ✓ Historial de canciones") print_separator("¡TESTS COMPLETADOS!") print() if __name__ == "__main__": test_integration()