forked from mtusi2026/mtusi2026lab4
Forward-port lab3 SQLAlchemy and Alembic foundation
Carry source f591fa64e525679a31c9db7f942d36c789e1a12f forward from 72a1e57. Preserve lab4 attachment transactions, reconciliation locks, quarantine, and existing schema data through verified legacy adoption. Keep report and evidence work in progress untouched.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import asyncio
|
||||
from urllib.parse import quote
|
||||
from uuid import uuid4
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from httpx import AsyncClient
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from conftest import PASSWORD, actor, keyed, make_chat, new_user, register, running_app, scalar
|
||||
from messenger.identity.infrastructure.postgres import UserRow
|
||||
from messenger.messaging.infrastructure.postgres import ChatMemberRow, ChatRow
|
||||
|
||||
REGISTRATIONS = 25
|
||||
|
||||
@@ -65,8 +68,8 @@ async def test_rejected_registration_leaves_no_trace() -> None:
|
||||
"/api/v1/users", json={"username": "AB", "display_name": "", "password": PASSWORD}
|
||||
)
|
||||
assert invalid.status_code == 400
|
||||
sql = "SELECT count(*) FROM users WHERE username = $1"
|
||||
assert await scalar(sql, alice["username"]) == 1
|
||||
sql = select(func.count()).select_from(UserRow).where(UserRow.username == alice["username"])
|
||||
assert await scalar(sql) == 1
|
||||
|
||||
|
||||
async def test_failed_chat_creation_rolls_back_both_tables() -> None:
|
||||
@@ -83,9 +86,15 @@ async def test_failed_chat_creation_rolls_back_both_tables() -> None:
|
||||
assert rejected.json()["error"]["code"] == "invalid_request"
|
||||
after = (await client.get("/api/v1/chats?limit=100", headers=actor(alice))).json()
|
||||
assert after["items"] == before["items"]
|
||||
assert await scalar("SELECT count(*) FROM chats WHERE title = $1", title) == 0
|
||||
members = "SELECT count(*) FROM chat_members WHERE user_id = $1::uuid"
|
||||
assert await scalar(members, alice["id"]) == 0
|
||||
assert (
|
||||
await scalar(select(func.count()).select_from(ChatRow).where(ChatRow.title == title)) == 0
|
||||
)
|
||||
members = (
|
||||
select(func.count())
|
||||
.select_from(ChatMemberRow)
|
||||
.where(ChatMemberRow.user_id == UUID(alice["id"]))
|
||||
)
|
||||
assert await scalar(members) == 0
|
||||
|
||||
|
||||
async def test_rejected_message_does_not_enter_history() -> None:
|
||||
|
||||
Reference in New Issue
Block a user