docs(06.2): capture phase context + fix admin user creation 500
- Phase 6.2 CONTEXT.md: cloud-delete propagation, SHARE-03/05, audit log CSV export fix, daily export UI, user handle display - Fix: admin create_user missing session.flush() before write_audit_log caused FK violation on PostgreSQL (silent on SQLite) - Regression test: test_create_user_writes_audit_log in test_admin_api.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,7 +21,8 @@ import pytest_asyncio
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from db.models import Quota, User
|
||||
from db.models import AuditLog, Quota, User
|
||||
from sqlalchemy import select
|
||||
from deps.auth import get_current_admin
|
||||
from deps.db import get_db
|
||||
from services.auth import hash_password
|
||||
@@ -140,6 +141,24 @@ async def test_create_user_sets_password_must_change(admin_client):
|
||||
assert user.password_must_change is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_user_writes_audit_log(admin_client):
|
||||
"""POST /api/admin/users → 201 and audit_log row created (regression: FK ordering bug)."""
|
||||
client, _admin, session = admin_client
|
||||
body = {
|
||||
"handle": "auditcheck_user",
|
||||
"email": "auditcheck@example.com",
|
||||
"password": "AuditCheck1@Pass",
|
||||
"role": "user",
|
||||
}
|
||||
resp = await client.post("/api/admin/users", json=body)
|
||||
assert resp.status_code == 201, f"expected 201, got {resp.status_code}: {resp.text}"
|
||||
result = await session.execute(
|
||||
select(AuditLog).where(AuditLog.event_type == "admin.user_created")
|
||||
)
|
||||
assert result.scalars().first() is not None, "audit log entry not created after user creation"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_user_weak_password(admin_client):
|
||||
"""POST /api/admin/users with weak password → 422."""
|
||||
|
||||
Reference in New Issue
Block a user