-
Notifications
You must be signed in to change notification settings - Fork 17
added python static liveness check #425
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
Changes from 1 commit
df2294b
e48f307
2b5d097
d95da83
e81f294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from .media_response import MediaResponse | ||
|
|
||
|
|
||
| class ImageResponse(object): | ||
| """ | ||
| Represents an image resource within a static liveness check | ||
| """ | ||
|
|
||
| def __init__(self, data=None): | ||
| """ | ||
| :param data: the data to parse | ||
| :type data: dict or None | ||
| """ | ||
| if data is None: | ||
| data = dict() | ||
|
Check warning on line 18 in yoti_python_sdk/doc_scan/session/retrieve/image_response.py
|
||
|
|
||
| self.__media = ( | ||
| MediaResponse(data["media"]) if "media" in data.keys() else None | ||
| ) | ||
|
|
||
| @property | ||
| def media(self): | ||
| """ | ||
| Returns the media information for the image | ||
|
|
||
| :return: the media | ||
| :rtype: MediaResponse or None | ||
| """ | ||
| return self.__media | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from .resource_response import ResourceResponse | ||
mehmet-yoti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from .liveness_resource_response import LivenessResourceResponse | ||
| from .image_response import ImageResponse | ||
|
|
||
|
|
||
| class StaticLivenessResourceResponse(LivenessResourceResponse): | ||
| """ | ||
| Represents a Static Liveness resource for a given session | ||
| """ | ||
|
|
||
| def __init__(self, data=None): | ||
| """ | ||
| :param data: the data to parse | ||
| :type data: dict or None | ||
| """ | ||
| if data is None: | ||
| data = dict() | ||
|
Check warning on line 20 in yoti_python_sdk/doc_scan/session/retrieve/static_liveness_resource_response.py
|
||
|
|
||
| LivenessResourceResponse.__init__(self, data) | ||
|
|
||
| self.__image = ( | ||
| ImageResponse(data["image"]) if "image" in data.keys() else None | ||
| ) | ||
|
|
||
| @property | ||
| def image(self): | ||
| """ | ||
| Returns the associated image for the static liveness resource | ||
| :return: the image | ||
| :rtype: ImageResponse or None | ||
| """ | ||
| return self.__image | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import unittest | ||
| import json | ||
|
|
||
mehmet-yoti marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from yoti_python_sdk.doc_scan.session.retrieve.static_liveness_resource_response import ( | ||
| StaticLivenessResourceResponse, | ||
| ) | ||
| from yoti_python_sdk.doc_scan.session.retrieve.image_response import ImageResponse | ||
| from yoti_python_sdk.doc_scan.session.retrieve.media_response import MediaResponse | ||
|
|
||
|
|
||
| class StaticLivenessResourceResponseTest(unittest.TestCase): | ||
| def test_should_parse_static_liveness_resource(self): | ||
| data = { | ||
| "id": "bbbbbbb-5717-4562-b3fc-2c963f66afa6", | ||
| "source": {"type": "END_USER"}, | ||
| "liveness_type": "STATIC", | ||
| "image": { | ||
| "media": { | ||
| "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", | ||
| "type": "IMAGE", | ||
| "created": "2021-06-11T11:39:24Z", | ||
| "last_updated": "2021-06-11T11:39:24Z", | ||
| } | ||
| }, | ||
| "tasks": [], | ||
| } | ||
|
|
||
| result = StaticLivenessResourceResponse(data) | ||
|
|
||
| assert result.id == "bbbbbbb-5717-4562-b3fc-2c963f66afa6" | ||
| assert result.liveness_type == "STATIC" | ||
| assert isinstance(result.image, ImageResponse) | ||
| assert isinstance(result.image.media, MediaResponse) | ||
| assert result.image.media.id == "3fa85f64-5717-4562-b3fc-2c963f66afa6" | ||
| assert result.image.media.type == "IMAGE" | ||
|
|
||
| def test_should_handle_missing_image(self): | ||
| data = { | ||
| "id": "test-id", | ||
| "liveness_type": "STATIC", | ||
| "tasks": [], | ||
| } | ||
|
|
||
| result = StaticLivenessResourceResponse(data) | ||
|
|
||
| assert result.id == "test-id" | ||
| assert result.liveness_type == "STATIC" | ||
| assert result.image is None | ||
|
|
||
| def test_should_parse_media_id_for_retrieval(self): | ||
| data = { | ||
| "id": "resource-id", | ||
| "liveness_type": "STATIC", | ||
| "image": { | ||
| "media": { | ||
| "id": "media-id-123", | ||
| "type": "IMAGE", | ||
| "created": "2021-06-11T11:39:24Z", | ||
| "last_updated": "2021-06-11T11:39:24Z", | ||
| } | ||
| }, | ||
| "tasks": [], | ||
| } | ||
|
|
||
| result = StaticLivenessResourceResponse(data) | ||
|
|
||
| # Verify we can access the media ID for content retrieval | ||
| assert result.image is not None | ||
| assert result.image.media is not None | ||
| assert result.image.media.id == "media-id-123" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Uh oh!
There was an error while loading. Please reload this page.