Files
mtusi2026lab7-safronov/student-tests/test_data_storage.py
ricoromaandClaude Opus 5.5 089d78609d chore: port lab 6 solution into the lab 7 skeleton
Source: mtusi2026lab6-safronov, solution/bvt2301-safronov, 6c6a065.
Files follow AGENTS.md, "Переход в следующую лабу". Contracts, public
tests, README, REPORT and evidence of lab 6 are not carried over; infra
and scripts of the lab 7 skeleton stay as they are.
Makefile is the lab 6 one with the lab 7 skeleton part restored
(HTTPS BASE_URL on 8443, test-security); .gitignore and .dockerignore
are taken from lab 6 because both skeletons have the same files;
.env.example is the lab 6 one without changes.
The compose project, image and CI prefix are renamed to lab7, and
references to the previous lab now name lab6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 03:59:04 +03:00

72 lines
2.2 KiB
Python

"""Спек `data-storage`.
Гонки — в `test_race.py`; рестарт, отказы БД и пул — исключения в
`spec_coverage.py`.
"""
from typing import Any
import pytest
import images
from api_client import API, Actor, Api, new_key
from contract import assert_ok
@pytest.mark.spec("data-storage", "Созданное видно сразу")
def test_created_user_visible_at_once(api: Api) -> None:
for _ in range(5):
actor = api.register()
resp = api.request("GET", f"{API}/users/me", actor=actor)
assert assert_ok(resp, 200, "User") == actor.user
@pytest.mark.spec("data-storage", "Порядок участников")
def test_member_order_kept(api: Api, alice: Actor, bob: Actor) -> None:
# порядок [bob, alice] из запроса не совпадает с порядком регистрации;
# «в том числе после рестарта» — evidence/storage/restart.md
created = api.create_chat(bob, alice, title="Порядок участников")
expected = [bob.id, alice.id]
assert created["member_ids"] == expected
resp = api.request("GET", f"{API}/chats/{created['id']}", actor=alice)
assert assert_ok(resp, 200, "Chat")["member_ids"] == expected
listed = {
chat["id"]: chat["member_ids"]
for page in api.chat_pages(alice)
for chat in page["items"]
}
assert listed[created["id"]] == expected
@pytest.mark.spec("data-storage", "Порядок вложений")
def test_attachment_order_kept(
api: Api,
alice: Actor,
chat: dict[str, Any],
) -> None:
a, b, c = (
api.upload(alice, chat["id"], images.sample_png())["id"]
for _ in range(3)
)
key = new_key()
order = [c, a, b]
sent = api.send_message(
alice,
chat["id"],
"порядок",
key=key,
attachment_ids=order,
)
assert sent["attachment_ids"] == order
assert api.all_messages(alice, chat["id"]) == [sent]
replay = api.send_message(
alice,
chat["id"],
"порядок",
key=key,
attachment_ids=order,
)
assert replay["attachment_ids"] == order