- Agregar 46 tests de integración (auth, multi-tenancy, tickets) - Crear estructura organizada tests/integration/ y tests/unit/ - Implementar fixtures completas para testing con BD separada - Agregar conftest_integration.py con setup async - Mover scripts PowerShell de testing a tests/scripts/ - Actualizar pytest.ini con markers y configuración - Crear run_tests.sh script ejecutable para testing - Documentación completa en README_TESTS.md - Fix: Remover opciones obsoletas de TypeScript (importsNotUsedAsValues) Tests implementados: - Authentication: 15 tests (login, refresh, permisos, seguridad) - Multi-tenancy: 13 tests (aislamiento, validaciones, seguridad B2B) - Tickets: 18 tests (CRUD, filtros, permisos por rol) - Unit: 10 tests básicos - Verificación: 8 tests de setup Base de datos de testing: servicemanager_test (separada de producción) Cobertura estimada: ~40% (desde 5%) Próximos pasos: Agregar tests de SLA, attachments, auditoría
79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
"""
|
|
Quick Test Verification - ServiceManagerWeb
|
|
|
|
Test rápido para verificar que la configuración de tests funciona correctamente.
|
|
"""
|
|
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
pytest_plugins = ['tests.conftest_integration']
|
|
|
|
|
|
@pytest.mark.integration
|
|
class TestSetupVerification:
|
|
"""Verificar que el setup de tests funciona."""
|
|
|
|
async def test_client_fixture_works(self, client: AsyncClient):
|
|
"""Test que el fixture de client HTTP funciona."""
|
|
assert client is not None
|
|
assert client.base_url == "http://test"
|
|
|
|
async def test_database_connection(self, db_session):
|
|
"""Test que la conexión a BD de testing funciona."""
|
|
assert db_session is not None
|
|
|
|
# Ejecutar query simple
|
|
from sqlalchemy import text
|
|
result = await db_session.execute(text("SELECT 1"))
|
|
assert result.scalar() == 1
|
|
|
|
async def test_tenant_fixture_creates_tenant(self, test_tenant):
|
|
"""Test que el fixture de tenant funciona."""
|
|
assert test_tenant is not None
|
|
assert test_tenant.name == "Test Company"
|
|
assert test_tenant.slug == "test-company"
|
|
|
|
async def test_user_fixtures_work(self, test_admin_user, test_agent_user, test_client_user):
|
|
"""Test que los fixtures de usuarios funcionan."""
|
|
assert test_admin_user.role.value == "ADMIN"
|
|
assert test_agent_user.role.value == "AGENT"
|
|
assert test_client_user.role.value == "CLIENT_USER"
|
|
|
|
async def test_auth_token_generation(self, admin_token):
|
|
"""Test que la generación de tokens funciona."""
|
|
assert admin_token is not None
|
|
assert isinstance(admin_token, str)
|
|
assert len(admin_token) > 20
|
|
|
|
async def test_health_endpoint(self, client: AsyncClient):
|
|
"""Test que el endpoint de health funciona."""
|
|
response = await client.get("/health")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "healthy"
|
|
|
|
|
|
@pytest.mark.integration
|
|
class TestBasicEndpoints:
|
|
"""Tests básicos de endpoints para verificar conectividad."""
|
|
|
|
async def test_health_endpoint_detailed(self, client: AsyncClient):
|
|
"""Test del endpoint de health detallado."""
|
|
response = await client.get("/v1/health/detailed")
|
|
assert response.status_code == 200
|
|
|
|
async def test_login_endpoint_exists(self, client: AsyncClient):
|
|
"""Test que el endpoint de login responde."""
|
|
# Enviar credenciales inválidas para verificar que el endpoint existe
|
|
response = await client.post(
|
|
"/v1/auth/login",
|
|
json={
|
|
"email": "nonexistent@test.com",
|
|
"password": "wrong",
|
|
"tenant_slug": "nonexistent"
|
|
}
|
|
)
|
|
# Debe responder (aunque con error)
|
|
assert response.status_code in [401, 404, 422]
|