Forward the lab 4 foundation and migrate the lab 5 pipeline to SQLAlchemy

This commit is contained in:
Artyom
2026-11-06 09:12:25 +03:00
parent ae9f60fe1f
commit 1217da5f5e
134 changed files with 8243 additions and 1409 deletions
+15 -6
View File
@@ -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: