⚡ fix(webdav): 改用独立分片流式合并并隔离测试协议
This commit is contained in:
1 parent
9a489297f4
commit
90089f793e
7 files changed
+255
-64
No files matched your search
@@ -0,0 +1,43 @@
|
||||
"""Independent immutable DAV parts; one streaming assembly, never PATCH/tempfile."""
|
||||
import hashlib
|
||||
from unittest.mock import patch
|
||||
from tests.test_webdav_offset_upload import WebDAVFixture
|
||||
|
||||
|
||||
class WebDAVStreamTests(WebDAVFixture):
|
||||
async def asyncSetUp(self):
|
||||
await super().asyncSetUp()
|
||||
from core.storage import WebDAVFileStorage
|
||||
self.mode_patch = patch.object(WebDAVFileStorage, 'chunk_upload_mode', return_value='webdav-stream')
|
||||
self.mode_patch.start()
|
||||
|
||||
async def asyncTearDown(self):
|
||||
self.mode_patch.stop()
|
||||
await super().asyncTearDown()
|
||||
|
||||
async def test_stream_upload_has_only_immutable_parts_and_one_final_put(self):
|
||||
uid=await self.upload_all()
|
||||
before=len(self.calls)
|
||||
with patch('core.storage.tempfile.NamedTemporaryFile',side_effect=AssertionError('no local whole-file temporary')):
|
||||
done=await self.complete(uid)
|
||||
self.assertEqual(done.status_code,200,done.text)
|
||||
self.assertEqual(list(self.files.values()),[self.payload])
|
||||
self.assertFalse(any(c[0]=='PATCH' for c in self.calls))
|
||||
puts=[c for c in self.calls[before:] if c[0]=='PUT']
|
||||
self.assertEqual(len(puts),1);self.assertEqual(puts[0][3],len(self.payload))
|
||||
|
||||
async def test_bad_remote_part_is_not_published(self):
|
||||
uid=await self.upload_all()
|
||||
part=next(k for k in self.files if k.endswith('/1.part'))
|
||||
self.files[part]=b'XXXXXXXX'
|
||||
done=await self.complete(uid);self.assertIn(done.status_code,(400,503))
|
||||
from apps.base.models import FileCodes
|
||||
self.assertEqual(await FileCodes.all().count(),0)
|
||||
await self.client.delete(f'/chunk/upload/{uid}');self.assertFalse(self.files)
|
||||
|
||||
async def test_failed_part_put_retries_without_mutating_existing_cloud_object(self):
|
||||
uid=await self.init();await self.chunk(uid,0)
|
||||
from apps.base.models import UploadChunk
|
||||
await UploadChunk.filter(upload_id=uid,chunk_index=0).delete()
|
||||
self.assertEqual((await self.chunk(uid,0)).status_code,200)
|
||||
self.assertFalse(any(c[0]=='PATCH' for c in self.calls))
|
||||
Reference in new issue
Block a user