refactor code
This commit is contained in:
@@ -53,12 +53,14 @@ class CriticalTests(unittest.IsolatedAsyncioTestCase):
|
||||
'content_type': 'image/png', 'size_bytes': 1, 'sha256': 'unused',
|
||||
}
|
||||
store.complete_attachment_job.return_value = committed
|
||||
store.ready_seconds.return_value = 0.25
|
||||
s3.settings = SimpleNamespace(max_pixels=40000000)
|
||||
s3.download_key.return_value = b'fixture'
|
||||
s3.delete.side_effect = RuntimeError('storage temporarily unavailable')
|
||||
payload = {'attachment_id': str(uuid4())}
|
||||
with patch('src.worker.render_isolated', return_value=[('thumbnail', b'jpeg', 'image/jpeg', 1, 1)]):
|
||||
await process(store, s3, payload, 60)
|
||||
outcome = await process(store, s3, payload, 60)
|
||||
self.assertEqual(outcome, "success" if committed else "skipped")
|
||||
self.assertEqual(store.complete_attachment_job.call_args.args[-1], stamp)
|
||||
return store, s3
|
||||
|
||||
@@ -71,6 +73,14 @@ class CriticalTests(unittest.IsolatedAsyncioTestCase):
|
||||
_, s3 = await self.run_processing(False)
|
||||
s3.delete.assert_not_awaited()
|
||||
|
||||
async def test_duplicate_is_skipped_not_successful(self):
|
||||
store, s3 = AsyncMock(), AsyncMock()
|
||||
store.claim_attachment_job.return_value = None
|
||||
result = await process(store, s3, {'attachment_id': str(uuid4())}, 60)
|
||||
self.assertEqual(result, 'skipped')
|
||||
store.complete_attachment_job.assert_not_awaited()
|
||||
s3.copy.assert_not_awaited()
|
||||
|
||||
async def test_stale_claim_cannot_publish_metadata(self):
|
||||
store = PostgresStore('unused')
|
||||
connection = AsyncMock()
|
||||
|
||||
Reference in New Issue
Block a user