diff --git a/main.py b/main.py index 89055e4..86889a4 100644 --- a/main.py +++ b/main.py @@ -38,4 +38,9 @@ async def read_random_file(): path = f"{IMAGEDIR}{files[random_index]}" - return FileResponse(path) \ No newline at end of file + return FileResponse(path) + +@app.delete("/delete/{filename}") +async def delete_file(filename: str): + os.remove(f"{IMAGEDIR}/{filename}") + return {"message": "Face deleted successfully"} diff --git a/test-faces/c8866490-5fbe-45fe-8ac0-38652ec779bd.jpg b/test-faces/c8866490-5fbe-45fe-8ac0-38652ec779bd.jpg deleted file mode 100644 index 7155804..0000000 Binary files a/test-faces/c8866490-5fbe-45fe-8ac0-38652ec779bd.jpg and /dev/null differ diff --git a/testing/test_register_face.py b/testing/test_register_face.py index 623fb7a..f3c0779 100644 --- a/testing/test_register_face.py +++ b/testing/test_register_face.py @@ -1,55 +1,31 @@ -# import pytest -# from starlette.testclient import TestClient -# from ..main import app -# import os - -# IMAGEDIR = "/test-faces" - -# def test_register_face(): -# client = TestClient(app) -# with open('test_image.jpg', 'rb') as test_file: -# response = client.post( -# "/upload/", -# files={"file": ("test_image.jpg", test_file, "image/jpeg")}, -# ) - -# assert response.status_code == 200 -# assert 'filename' in response.json() - -# # Cleanup: remove the uploaded file after test -# os.remove(f"{IMAGEDIR}{response.json()['filename']}") - +import pytest import requests -import base64 - -# Open the image file in binary mode, read it, and encode it to base64 -# with open('test-faces/07c64ef1-b32e-4396-97ea-0894249d58ee.jpg', 'rb') as image_file: -# encoded_string = base64.b64encode(image_file.read()).decode('utf-8') - -# # Define the URL where you want to send the POST request -# url = "http://localhost:8000/upload/" -# # Define the headers for the POST request -# headers = {'Content-Type': 'application/json'} -# # Define the body of the POST request -# data = {"file": encoded_string} +def test_register_face(): + with open('test-faces/07c64ef1-b32e-4396-97ea-0894249d58ee.jpg', 'rb') as image_file: + url = "http://localhost:8000/upload/" + response = requests.post(url, files={'file': image_file}) -# # Send the POST request -# response = requests.post(url, headers=headers, json=data) - -# # Print the response -# print(response.json()) - -import requests + assert response.status_code == 200 + filename = response.json()['filename'] + url = f"http://localhost:8000/delete/{filename}" + response = requests.delete(url) + assert response.status_code == 200 + assert response.json() == {'message': 'Face deleted successfully'} + + + + # assert response.json() == {'message': 'Face registered successfully'} # Open the image file in binary mode -with open('test-faces/07c64ef1-b32e-4396-97ea-0894249d58ee.jpg', 'rb') as image_file: - # Define the URL where you want to send the POST request - url = "http://localhost:8000/upload/" +# with open('test-faces/07c64ef1-b32e-4396-97ea-0894249d58ee.jpg', 'rb') as image_file: +# # Define the URL where you want to send the POST request +# url = "http://localhost:8000/upload/" - # Send the POST request with the file - response = requests.post(url, files={'file': image_file}) +# # Send the POST request with the file +# response = requests.post(url, files={'file': image_file}) - # Print the response - print(response.json()) \ No newline at end of file +# # Print the response +# assert response.status_code == 200 +# # print(response.json()) \ No newline at end of file