From 02550d4f66da3194c1b03112a189c56557bed74d Mon Sep 17 00:00:00 2001 From: Zach Fuller Date: Fri, 19 Jul 2024 23:20:12 -0700 Subject: [PATCH] added test for delete file --- tests/test_delete_file.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/test_delete_file.py diff --git a/tests/test_delete_file.py b/tests/test_delete_file.py new file mode 100644 index 0000000..b90d6ab --- /dev/null +++ b/tests/test_delete_file.py @@ -0,0 +1,27 @@ +from typing import Any +from uuid import uuid4 + +import pytest +from httpx import AsyncClient +from smolvault.models import FileUploadDTO + + +@pytest.mark.asyncio() +@pytest.mark.usefixtures("_test_bucket") +async def test_delete_file(client: AsyncClient, camera_img: bytes) -> None: + # first upload the file + filename = f"{uuid4().hex[:6]}-camera.png" + expected_obj = FileUploadDTO(name=filename, size=len(camera_img), content=camera_img, tags="camera,photo") + expected = expected_obj.model_dump(exclude={"content", "upload_timestamp", "tags"}) + response = await client.post( + "/file/upload", files={"file": (filename, camera_img, "image/png")}, data={"tags": "camera,photo"} + ) + actual: dict[str, Any] = response.json() + actual.pop("upload_timestamp") + assert response.status_code == 201 + assert actual == expected + + # now delete the file + response = await client.delete(f"/file/{filename}") + assert response.status_code == 200 + assert response.json() == {"message": "File deleted successfully", "record": expected} # TODO: Fix this assertion