Forward the lab 4 foundation and migrate the lab 5 pipeline to SQLAlchemy
This commit is contained in:
@@ -4,8 +4,10 @@ from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient, Response
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from conftest import actor, keyed, make_chat, register, running_app, scalar
|
||||
from messenger.messaging.infrastructure.postgres import IdempotencyKeyRow
|
||||
|
||||
INVALID_KEYS = ["", "k" * 129, "два слова", "a b", "a/b", "ключ"]
|
||||
|
||||
@@ -93,12 +95,22 @@ async def test_key_is_scoped_by_user_and_chat(client: AsyncClient) -> None:
|
||||
bob = await register(client, "bob")
|
||||
chat = await make_chat(client, alice, bob)
|
||||
other = await make_chat(client, alice)
|
||||
ids = {
|
||||
(await send(client, chat, alice, "алиса", "shared-1")).json()["id"],
|
||||
(await send(client, chat, bob, "боб", "shared-1")).json()["id"],
|
||||
(await send(client, other, alice, "другой чат", "shared-1")).json()["id"],
|
||||
}
|
||||
cases = [(chat, alice, "алиса"), (chat, bob, "боб"), (other, alice, "другой чат")]
|
||||
messages = []
|
||||
for target, user, text in cases:
|
||||
response = await send(client, target, user, text, "shared-1")
|
||||
assert response.status_code == 201
|
||||
message = response.json()
|
||||
assert (message["chat_id"], message["sender_id"], message["text"]) == (
|
||||
target["id"],
|
||||
user["id"],
|
||||
text,
|
||||
)
|
||||
messages.append(message)
|
||||
ids = {message["id"] for message in messages}
|
||||
assert len(ids) == 3
|
||||
for (target, user, text), message in zip(cases, messages, strict=True):
|
||||
assert (await send(client, target, user, text, "shared-1")).json() == message
|
||||
|
||||
|
||||
async def test_replay_checks_session_and_access_again(client: AsyncClient) -> None:
|
||||
@@ -142,4 +154,9 @@ async def test_concurrent_retries_through_two_replicas_store_one_message() -> No
|
||||
}
|
||||
assert all(response.json() == responses[0].json() for response in responses)
|
||||
assert [item["text"] for item in await history(second, chat, alice)] == [text]
|
||||
assert await scalar("SELECT count(*) FROM idempotency_keys WHERE key = $1", key) == 1
|
||||
assert (
|
||||
await scalar(
|
||||
select(func.count()).select_from(IdempotencyKeyRow).where(IdempotencyKeyRow.key == key)
|
||||
)
|
||||
== 1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user