feat: добавить reconciler PostgreSQL и S3

This commit is contained in:
2026-11-05 21:21:43 +03:00
parent 0ed4b9cea5
commit a3bbdeef42
12 changed files with 751 additions and 15 deletions
+42
View File
@@ -6,6 +6,8 @@ from uuid import uuid4
import pytest
from app.domain.errors import Conflict
from app.domain.models import Attachment
from app.domain.models import User
from app.services.attachments import AttachmentService
@@ -30,6 +32,19 @@ class RecordingStorage:
self.removed_key = key
class FailedAttachmentRepository:
def __init__(self, attachment):
self.attachment = attachment
async def get_for_member(self, attachment_id, user_id):
return self.attachment
class StorageThatMustNotBeRead:
async def get(self, key):
raise AssertionError('failed attachment must not read S3')
def test_uploaded_object_is_removed_when_metadata_commit_fails():
storage = RecordingStorage()
service = AttachmentService(FailingRepository(), storage, 10 * 1024 * 1024, 40_000_000)
@@ -52,3 +67,30 @@ def test_uploaded_object_is_removed_when_metadata_commit_fails():
assert storage.put_key is not None
assert storage.removed_key == storage.put_key
def test_failed_attachment_content_returns_conflict_without_s3_read():
now = datetime.now(timezone.utc)
attachment = Attachment(
id=uuid4(),
chat_id=uuid4(),
owner_id=uuid4(),
filename='missing.png',
object_key=f'originals/{uuid4()}',
content_type='image/png',
size_bytes=1,
sha256='0' * 64,
width=1,
height=1,
status='failed',
error_code='original_missing',
created_at=now,
updated_at=now,
)
service = AttachmentService(
FailedAttachmentRepository(attachment), StorageThatMustNotBeRead(), 1, 1
)
actor = User(uuid4(), 'tester', 'Tester', now)
with pytest.raises(Conflict, match='недоступен'):
asyncio.run(service.content(actor, attachment.id))