T05: Calendar plugin backend — appointments + tasks + kanban + ICS + resources + recurrence — 69 tests, 86.87% coverage
This commit is contained in:
+66
-1
@@ -36,6 +36,17 @@ from app.models.role import Role
|
||||
from app.models.tenant import Tenant
|
||||
from app.models.user import User, UserTenant
|
||||
from app.models.workflow import Workflow, WorkflowInstance, WorkflowStepHistory # noqa: F401
|
||||
from app.plugins.builtins.calendar import CalendarPlugin # noqa: F401
|
||||
from app.plugins.builtins.calendar.models import ( # noqa: F401
|
||||
Calendar,
|
||||
CalendarEntry,
|
||||
CalendarEntryLink,
|
||||
CalendarShare,
|
||||
Resource,
|
||||
ResourceBooking,
|
||||
Subtask,
|
||||
UserCalendarVisibility,
|
||||
)
|
||||
from app.plugins.builtins.dms import DmsPlugin # noqa: F401
|
||||
from app.plugins.builtins.dms.models import File as DmsFile # noqa: F401
|
||||
from app.plugins.builtins.dms.models import Folder # noqa: F401
|
||||
@@ -103,7 +114,7 @@ def clean_tables(db_setup):
|
||||
# TRUNCATE all tables with CASCADE — fast and reliable isolation
|
||||
conn.execute(
|
||||
text(
|
||||
"TRUNCATE TABLE files, folders, entity_links, share_links, permissions, tag_assignments, tags, workflow_step_history, workflow_instances, workflows, ai_messages, ai_conversations, plugin_migrations, plugins, company_contacts, contacts, api_tokens, password_reset_tokens, notifications, deletion_log, audit_log, sessions, roles, companies, user_tenants, users, tenants CASCADE;"
|
||||
"TRUNCATE TABLE resource_bookings, resources, subtasks, user_calendar_visibility, calendar_shares, calendar_entry_links, calendar_entries, calendars, files, folders, entity_links, share_links, permissions, tag_assignments, tags, workflow_step_history, workflow_instances, workflows, ai_messages, ai_conversations, plugin_migrations, plugins, company_contacts, contacts, api_tokens, password_reset_tokens, notifications, deletion_log, audit_log, sessions, roles, companies, user_tenants, users, tenants CASCADE;"
|
||||
)
|
||||
)
|
||||
conn.commit()
|
||||
@@ -349,3 +360,57 @@ async def authed_client(
|
||||
assert resp.status_code == 200, f"DMS activate failed: {resp.text}"
|
||||
|
||||
return dms_client, seed
|
||||
|
||||
|
||||
# ─── Calendar Fixtures ───
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def calendar_app(engine: AsyncEngine, redis_client):
|
||||
"""FastAPI app with Calendar plugin registered, installed, and activated."""
|
||||
reset_engine_for_testing(engine)
|
||||
app = create_app()
|
||||
|
||||
registry = reset_registry_for_testing()
|
||||
registry.initialize(engine, app)
|
||||
|
||||
container = get_container()
|
||||
await container.initialize()
|
||||
|
||||
registry.register_plugin(CalendarPlugin())
|
||||
reset_plugin_service_for_testing(registry)
|
||||
|
||||
# Pre-install and activate the plugin so routes are registered
|
||||
# (tests that use viewer accounts can't install/activate — require_admin blocks them)
|
||||
_sf = async_sessionmaker(bind=engine, expire_on_commit=False, class_=AsyncSession)
|
||||
async with _sf() as session:
|
||||
await registry.install(session, "calendar")
|
||||
await registry.activate(session, "calendar")
|
||||
await session.commit()
|
||||
|
||||
yield app
|
||||
await close_engine()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def calendar_client(calendar_app) -> AsyncClient:
|
||||
transport = ASGITransport(app=calendar_app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as c:
|
||||
yield c
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def calendar_authed_client(
|
||||
calendar_client: AsyncClient, db_session: AsyncSession
|
||||
) -> tuple[AsyncClient, dict]:
|
||||
"""Authenticated admin client with seeded data and calendar plugin activated."""
|
||||
seed = await seed_tenant_and_users(db_session)
|
||||
await login_client(calendar_client, "admin@tenanta.com")
|
||||
|
||||
# Install + activate calendar plugin
|
||||
resp = await calendar_client.post("/api/v1/plugins/calendar/install", headers=ORIGIN_HEADER)
|
||||
assert resp.status_code == 200, f"Calendar install failed: {resp.text}"
|
||||
resp = await calendar_client.post("/api/v1/plugins/calendar/activate", headers=ORIGIN_HEADER)
|
||||
assert resp.status_code == 200, f"Calendar activate failed: {resp.text}"
|
||||
|
||||
return calendar_client, seed
|
||||
|
||||
Reference in New Issue
Block a user