feat: upload - deel 03.02 - Skipp all toegevoegd
This commit is contained in:
@@ -49,13 +49,13 @@ class UploadApiGoldenTest(unittest.TestCase):
|
||||
app.dependency_overrides.clear()
|
||||
self.temp_dir.cleanup()
|
||||
|
||||
def _upload(self, *, target_path: str, filename: str, content: bytes) -> httpx.Response:
|
||||
def _upload(self, *, target_path: str, filename: str, content: bytes, overwrite: bool = False) -> httpx.Response:
|
||||
async def _run() -> httpx.Response:
|
||||
transport = httpx.ASGITransport(app=app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
|
||||
return await client.post(
|
||||
"/api/files/upload",
|
||||
data={"target_path": target_path},
|
||||
data={"target_path": target_path, "overwrite": "true" if overwrite else "false"},
|
||||
files={"file": (filename, content, "application/octet-stream")},
|
||||
)
|
||||
|
||||
@@ -184,3 +184,21 @@ class UploadApiGoldenTest(unittest.TestCase):
|
||||
self.assertEqual(history[0]["operation"], "upload")
|
||||
self.assertEqual(history[0]["status"], "failed")
|
||||
self.assertEqual(history[0]["error_code"], "already_exists")
|
||||
|
||||
def test_upload_overwrite_existing_file_success(self) -> None:
|
||||
existing = self.uploads_dir / "hello.txt"
|
||||
existing.write_text("existing", encoding="utf-8")
|
||||
|
||||
response = self._upload(
|
||||
target_path="storage1/uploads",
|
||||
filename="hello.txt",
|
||||
content=b"replacement",
|
||||
overwrite=True,
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual((self.uploads_dir / "hello.txt").read_bytes(), b"replacement")
|
||||
|
||||
history = self._get_history()
|
||||
self.assertEqual(history[0]["operation"], "upload")
|
||||
self.assertEqual(history[0]["status"], "completed")
|
||||
|
||||
Reference in New Issue
Block a user