Skip to content

Feature/duplicate checks #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="yk_face",
version="0.3.5",
version="0.3.6",
description="Python SDK for the YouFace API.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
35 changes: 35 additions & 0 deletions tests/test_face.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Face Integration Tests """
import os
import time
import string
import random
import asyncio
Expand All @@ -18,6 +19,7 @@

__image_file = './sample/detection1.jpg'
__person_id = "person1"
__person_id_duplicate = "person1_duplicate"
__template: str

__group_id_async = "test_face_sdk_py_group_async"
Expand Down Expand Up @@ -294,10 +296,43 @@ def test_group_add_person(use_async: bool, group_id: str, loop: asyncio.Abstract
person_id=__person_id,
face_template=__template
)
time.sleep(1)
except YoonikApiException:
assert False


@pytest.mark.parametrize('use_async, group_id', [
(True, __group_id_async),
(False, __group_id)
])
def test_group_add_duplicate_person(use_async: bool, group_id: str, loop: asyncio.AbstractEventLoop):
"""
Test sync and async group add_person request with duplicate check.
:param use_async: flag to use the async function
:param group_id: group identifier
:param loop: event loop for the current test
:return:
Passes if YoonikApiException is raised.
"""
with pytest.raises(YoonikApiException) as exception:
if use_async:
loop.run_until_complete(
YKF.group.add_person_async(
group_id=group_id,
person_id=__person_id_duplicate,
face_template=__template,
duplicate_check=True
)
)
else:
YKF.group.add_person(
group_id=group_id,
person_id=__person_id_duplicate,
face_template=__template,
duplicate_check=True
)
assert exception.value.status_code == 409

# @pytest.mark.parametrize('use_async, group_id', [
# (True, 'invalid_group1'),
# (False, 'invalid_group3')
Expand Down
14 changes: 10 additions & 4 deletions yk_face/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ async def list_ids_async(group_id: str) -> List[str]:
return await request_async('GET', url)


def add_person(group_id: str, person_id: str, face_template: str):
def add_person(group_id: str, person_id: str, face_template: str, duplicate_check=False):
"""Add a person to a group.
:param group_id:
ID of the group. `group_id` is created in `group.create`.
:param person_id:
Person ID.
:param face_template:
Biometric template to be associated with the provided `person_id` (obtained from `face.process`).
:param duplicate_check:
Set True to check if a template already exists with a different person_id.
:return:
"""
if group_id is None:
Expand All @@ -107,11 +109,12 @@ def add_person(group_id: str, person_id: str, face_template: str):
raise ValueError("Person ID must be specified.")

url = f'gallery/{group_id}/{person_id}'
template_request = Template(template=face_template).model_dump(mode='json')
template_request = Template(
template=face_template, duplicate_check=duplicate_check).model_dump(mode='json')
request('POST', url, json=template_request)


async def add_person_async(group_id: str, person_id: str, face_template: str):
async def add_person_async(group_id: str, person_id: str, face_template: str, duplicate_check=False):
"""
Add a person to a group.
Performs the request asynchronously.
Expand All @@ -121,6 +124,8 @@ async def add_person_async(group_id: str, person_id: str, face_template: str):
Person ID.
:param face_template:
Biometric template to be associated with the provided `person_id` (obtained from `face.process`).
:param duplicate_check:
Set True to check if a template already exists with a different person_id.
:return:
"""
if group_id is None:
Expand All @@ -129,7 +134,8 @@ async def add_person_async(group_id: str, person_id: str, face_template: str):
raise ValueError("Person ID must be specified.")

url = f'gallery/{group_id}/{person_id}'
template_request = Template(template=face_template).model_dump(mode='json')
template_request = Template(
template=face_template, duplicate_check=duplicate_check).model_dump(mode='json')
await request_async('POST', url, json=template_request)


Expand Down
Loading