# import pytest


    
# from .bullmaq_backup import bullmq_backup, list_backups, delete_backup, bullmq_delete_backup
# from .bullmq_sender import bullmq_sender
# import time
# from datetime import datetime, timezone

# @pytest.mark.skipif(db is None, reason="Requiere conexión a MongoDB real")
# def test_real_mongodb_backup():
#     """Test de backup usando MongoDB real (no mock)."""
#     print("🚀 Test con MongoDB REAL")
    
#     # Crear jobs reales
#     test_queue = "real_mongodb_test_queue"
#     job_ids = []
    
#     for i in range(3):
#         job_id = bullmq_sender(
#             worker=test_queue,
#             priority=5,
#             delay_sec=1,
#             message={"real_test": True, "index": i, "timestamp": datetime.now(timezone.utc).isoformat()},
#             job_id=f"real_test_job_{i}_{int(time.time())}"
#         )
#         job_ids.append(job_id)
#         print(f"✅ Job creado: {job_id}")
    
#     # Esperar registro
#     time.sleep(2)
    
#     # Backup con nombre único
#     backup_name = f"test_real_{datetime.now(timezone.utc).strftime('%Y%m%d_%H%M%S')}"
    
#     result = bullmq_backup(
#         db=db,
#         queue_names=[test_queue],
#         backup_name=backup_name
#     )
    
#     print(f"📊 Resultado backup: {result}")
    
#     # Verificaciones
#     assert result["status"] == "success", f"Backup falló: {result}"
#     assert result["backup_id"] == backup_name
    
#     # Verificar en DB real
#     collection = db["bullmqJobBackup"]
#     saved = collection.find_one({"backup_id": backup_name})
    
#     assert saved is not None, "Backup no encontrado en MongoDB real"
#     assert saved["backup_id"] == backup_name
#     assert "queues" in saved
    
#     print(f"✅ BACKUP REAL CREADO EN MONGODB:")
#     print(f"   📄 ID: {backup_name}")
#     print(f"   🆔 MongoDB _id: {saved['_id']}")
#     print(f"   📅 Fecha: {saved['created_at']}")
#     print(f"   📊 Jobs: {saved['total_jobs']}")
    
#     # Listar backups reales
#     backups = list_backups(db)
#     print(f"\\n📋 Backups totales en DB real: {len(backups)}")
    
#     for backup in backups[-5:]:  # Últimos 5
#         print(f"   📄 {backup['backup_id']} - {backup['total_jobs']} jobs")
    
#     return backup_name

# @pytest.mark.skipif(db is None, reason="Requiere conexión a MongoDB real")
# def test_list_real_backups():
#     """Listar backups reales en MongoDB."""
#     backups = list_backups(db)
#     print(f"\\n📋 BACKUPS REALES EN MONGODB:")
#     print(f"Total: {len(backups)}")
    
#     for i, backup in enumerate(backups):
#         print(f"{i+1}. {backup['backup_id']}")
#         print(f"   📅 {backup['created_at']}")
#         print(f"   📊 {backup['total_jobs']} jobs en {backup['total_queues']} queues")
#         print()
    
#     assert isinstance(backups, list)

# if __name__ == "__main__":
#     if db is None:
#         print("❌ No hay conexión a MongoDB real")
#         exit(1)
    
#     print("=== Test de Backup Real ===")
#     backup_name = test_real_mongodb_backup()
#     test_list_real_backups()
    
#     print(f"\\n🎯 Backup '{backup_name}' creado exitosamente en tu base de datos real!")
#     print(f"🔍 Verifica en MongoDB Compass o tu cliente MongoDB preferido")
#     print(f"📁 Colección: bullmqJobBackup")