Skip to content

Commit

Permalink
added test for delete file
Browse files Browse the repository at this point in the history
  • Loading branch information
fullerzz committed Jul 20, 2024
1 parent 797d59d commit 02550d4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_delete_file.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 02550d4

Please sign in to comment.