- Nuevo schema `crm` con 7 tablas multi-tenant (TenantScopedMixin + soft delete) - Módulos FastAPI por dominio: models/dto/service/routes (patrón example) - Métricas del dashboard (KPIs + embudo por etapa) - Conversión de prospecto → cuenta/contacto/oportunidad (idempotente) - Movimiento de oportunidad entre etapas (Kanban) con estado/probabilidad derivados - 25 permisos registrados en PermissionRegistry - Migración Alembic con upgrade/downgrade completos - 24 tests de servicios (pytest) en verde Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
from api.v1.modules.crm.accounts import service as accounts_service
|
|
from api.v1.modules.crm.accounts.dto import AccountCreate
|
|
from api.v1.modules.crm.contacts import service
|
|
from api.v1.modules.crm.contacts.dto import ContactCreate
|
|
|
|
T, C = 1, 1
|
|
|
|
|
|
def test_create_contact_rejects_unknown_account(db):
|
|
with pytest.raises(HTTPException) as exc:
|
|
service.create_contact(db, ContactCreate(first_name="Juan", account_id=999), T, C)
|
|
assert exc.value.status_code == 422
|
|
|
|
|
|
def test_create_and_list_by_account(db):
|
|
acc = accounts_service.create_account(db, AccountCreate(name="Empresa"), T, C)
|
|
contact = service.create_contact(
|
|
db,
|
|
ContactCreate(first_name="Ana", last_name="López", account_id=acc.id, is_primary=True),
|
|
T, C,
|
|
)
|
|
assert contact.account_id == acc.id
|
|
assert contact.is_primary is True
|
|
listed = service.get_contacts(db, T, C, account_id=acc.id)
|
|
assert len(listed) == 1 and listed[0].first_name == "Ana"
|
|
|
|
|
|
def test_contact_without_account_is_allowed(db):
|
|
contact = service.create_contact(db, ContactCreate(first_name="Suelto"), T, C)
|
|
assert contact.account_id is None
|