-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delete_file endpoint and test case
- Loading branch information
Showing
3 changed files
with
29 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
# # Print the response | ||
# assert response.status_code == 200 | ||
# # print(response.json()) |