mirror of
https://github.com/serengil/deepface.git
synced 2025-06-05 19:15:23 +00:00
for form data api tests, download files to local filesystem
This commit is contained in:
parent
60067e24a0
commit
0b38a3c11f
@ -1,16 +1,29 @@
|
|||||||
# built-in dependencies
|
# built-in dependencies
|
||||||
|
import os
|
||||||
import base64
|
import base64
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
# 3rd party dependencies
|
||||||
|
import gdown
|
||||||
|
|
||||||
# project dependencies
|
# project dependencies
|
||||||
from deepface.api.src.app import create_app
|
from deepface.api.src.app import create_app
|
||||||
from deepface.commons.logger import Logger
|
from deepface.commons.logger import Logger
|
||||||
|
|
||||||
logger = Logger()
|
logger = Logger()
|
||||||
|
|
||||||
|
IMG1_SOURCE = (
|
||||||
|
"https://raw.githubusercontent.com/serengil/deepface/refs/heads/master/tests/dataset/img1.jpg"
|
||||||
|
)
|
||||||
|
IMG2_SOURCE = (
|
||||||
|
"https://raw.githubusercontent.com/serengil/deepface/refs/heads/master/tests/dataset/img2.jpg"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestVerifyEndpoint(unittest.TestCase):
|
class TestVerifyEndpoint(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
download_test_images(IMG1_SOURCE)
|
||||||
|
download_test_images(IMG2_SOURCE)
|
||||||
app = create_app()
|
app = create_app()
|
||||||
app.config["DEBUG"] = True
|
app.config["DEBUG"] = True
|
||||||
app.config["TESTING"] = True
|
app.config["TESTING"] = True
|
||||||
@ -240,7 +253,7 @@ class TestVerifyEndpoint(unittest.TestCase):
|
|||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
|
|
||||||
def test_analyze_for_multipart_form_data(self):
|
def test_analyze_for_multipart_form_data(self):
|
||||||
with open("dataset/img1.jpg", "rb") as img_file:
|
with open("/tmp/img1.jpg", "rb") as img_file:
|
||||||
response = self.app.post(
|
response = self.app.post(
|
||||||
"/analyze",
|
"/analyze",
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
@ -258,8 +271,8 @@ class TestVerifyEndpoint(unittest.TestCase):
|
|||||||
logger.info("✅ analyze api for multipart form data test is done")
|
logger.info("✅ analyze api for multipart form data test is done")
|
||||||
|
|
||||||
def test_verify_for_multipart_form_data(self):
|
def test_verify_for_multipart_form_data(self):
|
||||||
with open("dataset/img1.jpg", "rb") as img1_file:
|
with open("/tmp/img1.jpg", "rb") as img1_file:
|
||||||
with open("dataset/img2.jpg", "rb") as img2_file:
|
with open("/tmp/img2.jpg", "rb") as img2_file:
|
||||||
response = self.app.post(
|
response = self.app.post(
|
||||||
"/verify",
|
"/verify",
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
@ -284,7 +297,7 @@ class TestVerifyEndpoint(unittest.TestCase):
|
|||||||
logger.info("✅ verify api for multipart form data test is done")
|
logger.info("✅ verify api for multipart form data test is done")
|
||||||
|
|
||||||
def test_represent_for_multipart_form_data(self):
|
def test_represent_for_multipart_form_data(self):
|
||||||
with open("dataset/img1.jpg", "rb") as img_file:
|
with open("/tmp/img1.jpg", "rb") as img_file:
|
||||||
response = self.app.post(
|
response = self.app.post(
|
||||||
"/represent",
|
"/represent",
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
@ -304,7 +317,7 @@ class TestVerifyEndpoint(unittest.TestCase):
|
|||||||
"/represent",
|
"/represent",
|
||||||
content_type="multipart/form-data",
|
content_type="multipart/form-data",
|
||||||
data={
|
data={
|
||||||
"img": "dataset/img1.jpg",
|
"img": "/tmp/img1.jpg",
|
||||||
"model_name": "Facenet",
|
"model_name": "Facenet",
|
||||||
"detector_backend": "mtcnn",
|
"detector_backend": "mtcnn",
|
||||||
},
|
},
|
||||||
@ -313,3 +326,12 @@ class TestVerifyEndpoint(unittest.TestCase):
|
|||||||
result = response.json
|
result = response.json
|
||||||
assert isinstance(result, dict)
|
assert isinstance(result, dict)
|
||||||
logger.info("✅ represent api for multipart form data and file path test is done")
|
logger.info("✅ represent api for multipart form data and file path test is done")
|
||||||
|
|
||||||
|
|
||||||
|
def download_test_images(url: str):
|
||||||
|
file_name = url.split("/")[-1]
|
||||||
|
target_file = f"/tmp/{file_name}"
|
||||||
|
if os.path.exists(target_file) is True:
|
||||||
|
return
|
||||||
|
|
||||||
|
gdown.download(url, target_file, quiet=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user