feat: крролик, по тщ 5 лаба

This commit is contained in:
Enterxx2
2026-11-10 12:38:09 +03:00
parent 1d8dfb7ea4
commit 595a959b96
65 changed files with 2692 additions and 216 deletions
@@ -82,18 +82,18 @@ def run(coro):
return asyncio.run(coro)
def test_success_stores_object_and_ready_row() -> None:
def test_success_stores_staging_and_queued_row() -> None:
stand = Stand()
data = png()
attachment = run(stand.upload(data))
assert attachment.sha256 == hashlib.sha256(data).hexdigest()
assert stand.attachments.statuses() == [AttachmentStatus.READY]
assert stand.attachments.statuses() == [AttachmentStatus.QUEUED]
[(stored, _)] = stand.storage.objects.values()
assert stored == data
[key] = stand.storage.objects
assert key.startswith("originals/") and "a.png" not in key
assert key.startswith("staging/originals/") and "a.png" not in key
# Строка записана до PUT, подтверждена после
assert stand.attachments.calls[:2] == ["create_pending", "mark_ready"]
assert stand.attachments.calls[:2] == ["create_pending", "mark_queued"]
def test_s3_failure_after_write_is_compensated() -> None:
@@ -109,7 +109,7 @@ def test_s3_failure_after_write_is_compensated() -> None:
def test_db_failure_between_s3_and_commit_is_compensated() -> None:
"""Объект записан в S3, подтверждение в БД не прошло"""
stand = Stand()
stand.attachments.fail.add("mark_ready")
stand.attachments.fail.add("mark_queued")
with pytest.raises(UnavailableError):
run(stand.upload())
assert stand.storage.objects == {}
@@ -122,7 +122,7 @@ def test_db_down_leaves_pending_row_that_janitor_cleans() -> None:
строкой pending; janitor после grace period удаляет и объект, и строку.
"""
stand = Stand()
stand.attachments.fail.update({"mark_ready", "claim_pending"})
stand.attachments.fail.update({"mark_queued", "claim_pending"})
with pytest.raises(UnavailableError):
run(stand.upload())
assert len(stand.storage.objects) == 1
@@ -140,7 +140,7 @@ def test_db_down_leaves_pending_row_that_janitor_cleans() -> None:
def test_s3_down_during_compensation_leaves_deleting_row_for_janitor() -> None:
stand = Stand()
stand.attachments.fail.add("mark_ready")
stand.attachments.fail.add("mark_queued")
stand.storage.fail.add("delete")
with pytest.raises(UnavailableError):
run(stand.upload())
@@ -241,12 +241,16 @@ def test_foreign_chat_is_404_before_reading_body() -> None:
chat_id = uuid4()
stand.chats.foreign.add(chat_id)
with pytest.raises(NotFoundError):
run(stand.service.upload(USER, chat_id, "a.png", "image/png", 10, chunks_of(b"")))
run(
stand.service.upload(
USER, chat_id, "a.png", "image/png", 10, chunks_of(b"")
)
)
def test_missing_variant_is_404() -> None:
stand = Stand()
attachment = run(stand.upload())
attachment = run(stand.upload()).model_copy(update={"status": "ready"})
async def get_for_member(attachment_id, member_id):
[key] = stand.storage.objects
@@ -258,4 +262,6 @@ def test_missing_variant_is_404() -> None:
)
assert content.content_length == attachment.size_bytes
with pytest.raises(NotFoundError):
run(stand.service.open_content(USER, attachment.id, AttachmentVariant.THUMBNAIL))
run(
stand.service.open_content(USER, attachment.id, AttachmentVariant.THUMBNAIL)
)