Remove root test .py files
This commit is contained in:
-109
@@ -1,109 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Script para testear la configuración de PayPal
|
||||
Ejecutar: python test_paypal.py
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
|
||||
def main() -> None:
|
||||
# Configurar Django solo cuando se ejecuta script manualmente.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings')
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
django.setup()
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
print("=" * 60)
|
||||
print("TEST DE CONFIGURACIÓN DE PAYPAL")
|
||||
print("=" * 60)
|
||||
|
||||
# Verificar configuración
|
||||
print("\n1. Verificando configuración en settings.py:")
|
||||
print(f" PAYPAL_MODE: {settings.PAYPAL_MODE}")
|
||||
print(f" PAYPAL_CLIENT_ID: {settings.PAYPAL_CLIENT_ID[:20]}..." if settings.PAYPAL_CLIENT_ID else " ❌ NO CONFIGURADO")
|
||||
print(f" PAYPAL_CLIENT_SECRET: {settings.PAYPAL_CLIENT_SECRET[:20]}..." if settings.PAYPAL_CLIENT_SECRET else " ❌ NO CONFIGURADO")
|
||||
|
||||
# Intentar importar paypalrestsdk
|
||||
print("\n2. Verificando SDK de PayPal:")
|
||||
try:
|
||||
import paypalrestsdk
|
||||
print(" ✓ paypalrestsdk importado correctamente")
|
||||
print(f" Versión: {paypalrestsdk.__version__ if hasattr(paypalrestsdk, '__version__') else 'Desconocida'}")
|
||||
except ImportError as e:
|
||||
print(f" ❌ Error: {e}")
|
||||
print(" SOLUCIÓN: uv add paypalrestsdk")
|
||||
sys.exit(1)
|
||||
|
||||
# Intentar conectar a PayPal
|
||||
print("\n3. Probando conexión a PayPal:")
|
||||
try:
|
||||
paypalrestsdk.configure({
|
||||
"mode": settings.PAYPAL_MODE,
|
||||
"client_id": settings.PAYPAL_CLIENT_ID,
|
||||
"client_secret": settings.PAYPAL_CLIENT_SECRET
|
||||
})
|
||||
print(" ✓ Configuración de PayPal aplicada")
|
||||
|
||||
# Intentar crear un pago de prueba
|
||||
print("\n4. Creando pago de prueba:")
|
||||
test_payment = paypalrestsdk.Payment({
|
||||
"intent": "sale",
|
||||
"payer": {
|
||||
"payment_method": "paypal"
|
||||
},
|
||||
"redirect_urls": {
|
||||
"return_url": "http://localhost:8000/test-return",
|
||||
"cancel_url": "http://localhost:8000/test-cancel"
|
||||
},
|
||||
"transactions": [
|
||||
{
|
||||
"amount": {
|
||||
"total": "10.00",
|
||||
"currency": "EUR",
|
||||
"details": {
|
||||
"subtotal": "10.00",
|
||||
"tax": "0",
|
||||
"shipping": "0"
|
||||
}
|
||||
},
|
||||
"description": "Pago de prueba",
|
||||
"item_list": {
|
||||
"items": [
|
||||
{
|
||||
"name": "Test Item",
|
||||
"sku": "test_1",
|
||||
"price": "10.00",
|
||||
"currency": "EUR",
|
||||
"quantity": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
if test_payment.create():
|
||||
print(" ✓ Pago creado exitosamente")
|
||||
print(f" Payment ID: {test_payment.id}")
|
||||
for link in test_payment.links:
|
||||
if link.rel == "approval_url":
|
||||
print(f" URL de aprobación: {link.href}")
|
||||
else:
|
||||
print(" ❌ Error al crear el pago:")
|
||||
if hasattr(test_payment, 'error') and test_payment.error:
|
||||
print(f" {test_payment.error}")
|
||||
|
||||
except Exception as e:
|
||||
print(f" ❌ Error de conexión: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("TEST COMPLETADO")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,85 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Script de prueba para el cacheo de productos en Redis
|
||||
Ejecutar: python test_product_cache.py
|
||||
"""
|
||||
import os
|
||||
import django
|
||||
|
||||
# Configurar Django
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings')
|
||||
django.setup()
|
||||
|
||||
from tienda.models import Product
|
||||
from django.core.cache import cache
|
||||
import time
|
||||
|
||||
def test_product_cache():
|
||||
"""Prueba el sistema de cacheo de productos"""
|
||||
print("=" * 60)
|
||||
print("TEST: Sistema de Cacheo de Productos en Redis")
|
||||
print("=" * 60)
|
||||
|
||||
# Obtener un producto de prueba
|
||||
try:
|
||||
product = Product.objects.first()
|
||||
if not product:
|
||||
print("❌ No hay productos en la base de datos para probar")
|
||||
return
|
||||
|
||||
product_id = product.id
|
||||
cache_key = f'product_{product_id}'
|
||||
|
||||
print(f"\n📦 Producto de prueba: {product.name} (ID: {product_id})")
|
||||
|
||||
# 1. Limpiar caché del producto
|
||||
cache.delete(cache_key)
|
||||
print(f"\n1️⃣ Caché limpiado")
|
||||
|
||||
# 2. Primera visita (debe cargar desde BD)
|
||||
print(f"\n2️⃣ Primera visita - Cargando desde BD...")
|
||||
start_time = time.time()
|
||||
cached_product = cache.get(cache_key)
|
||||
if cached_product is None:
|
||||
print(" ✅ No está en caché (esperado)")
|
||||
product_from_db = Product.objects.select_related('category', 'primary_image', 'creator').prefetch_related('secondary_images').get(id=product_id)
|
||||
cache.set(cache_key, product_from_db, 300)
|
||||
print(f" ✅ Producto cacheado por 5 minutos")
|
||||
db_time = (time.time() - start_time) * 1000
|
||||
|
||||
# 3. Segunda visita (debe cargar desde caché)
|
||||
print(f"\n3️⃣ Segunda visita - Cargando desde caché...")
|
||||
start_time = time.time()
|
||||
cached_product = cache.get(cache_key)
|
||||
if cached_product:
|
||||
print(f" ✅ Encontrado en caché: {cached_product.name}")
|
||||
cache_time = (time.time() - start_time) * 1000
|
||||
|
||||
# 4. Comparar tiempos
|
||||
print(f"\n⏱️ Comparación de rendimiento:")
|
||||
print(f" - Desde BD: {db_time:.2f}ms")
|
||||
print(f" - Desde caché: {cache_time:.2f}ms")
|
||||
speedup = db_time / cache_time if cache_time > 0 else float('inf')
|
||||
print(f" - Mejora: {speedup:.1f}x más rápido")
|
||||
|
||||
# 5. Verificar TTL
|
||||
ttl = cache.ttl(cache_key)
|
||||
print(f"\n⏳ TTL (tiempo de vida): {ttl} segundos (~5 minutos)")
|
||||
|
||||
# 6. Verificar en Redis
|
||||
print(f"\n🔍 Verificación en Redis:")
|
||||
print(f" - Clave: {cache_key}")
|
||||
print(f" - Base de datos: 1")
|
||||
print(f" - Comando para ver: valkey-cli -n 1 GET ':1:{cache_key}'")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("✅ TEST COMPLETADO EXITOSAMENTE")
|
||||
print("=" * 60)
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error durante el test: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_product_cache()
|
||||
Reference in New Issue
Block a user