Skip to content

Commit ed5cd62

Browse files
committed
SDK-1739: Add biometric consent support
1 parent 0a8a5fc commit ed5cd62

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

yoti_python_sdk/doc_scan/session/create/session_spec.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(
2020
requested_checks=None,
2121
requested_tasks=None,
2222
required_documents=None,
23+
block_biometric_consent=None,
2324
):
2425
"""
2526
:param client_session_token_ttl: the client session token TTL
@@ -38,6 +39,8 @@ def __init__(
3839
:type requested_tasks: list[RequestedTask] or None
3940
:param required_documents: the list of required documents
4041
:type required_documents: list[RequiredDocument] or None
42+
:param block_biometric_consent: block the collection of biometric consent
43+
:type block_biometric_consent: bool
4144
"""
4245
if requested_tasks is None:
4346
requested_tasks = []
@@ -54,6 +57,7 @@ def __init__(
5457
self.__requested_checks = requested_checks
5558
self.__requested_tasks = requested_tasks
5659
self.__required_documents = required_documents
60+
self.__block_biometric_consent = block_biometric_consent
5761

5862
@property
5963
def client_session_token_ttl(self):
@@ -138,6 +142,16 @@ def required_documents(self):
138142
"""
139143
return self.__required_documents
140144

145+
@property
146+
def block_biometric_consent(self):
147+
"""
148+
Whether or not to block the collection of biometric consent.
149+
150+
:return: block biometric consent
151+
:rtype: bool
152+
"""
153+
return self.__block_biometric_consent
154+
141155
def to_json(self):
142156
return remove_null_values(
143157
{
@@ -149,6 +163,7 @@ def to_json(self):
149163
"requested_tasks": self.requested_tasks,
150164
"sdk_config": self.sdk_config,
151165
"required_documents": self.required_documents,
166+
"block_biometric_consent": self.block_biometric_consent,
152167
}
153168
)
154169

@@ -167,6 +182,7 @@ def __init__(self):
167182
self.__requested_checks = []
168183
self.__requested_tasks = []
169184
self.__required_documents = []
185+
self.__block_biometric_consent = None
170186

171187
def with_client_session_token_ttl(self, value):
172188
"""
@@ -264,6 +280,18 @@ def with_required_document(self, required_document):
264280
self.__required_documents.append(required_document)
265281
return self
266282

283+
def with_block_biometric_consent(self, block_biometric_consent):
284+
"""
285+
Sets whether or not to block the collection of biometric consent
286+
287+
:param block_biometric_consent: block biometric consent
288+
:type block_biometric_consent: bool
289+
:return: the builder
290+
:rtype: SessionSpecBuilder
291+
"""
292+
self.__block_biometric_consent = block_biometric_consent
293+
return self
294+
267295
def build(self):
268296
"""
269297
Builds a :class:`SessionSpec` using the supplied values
@@ -280,4 +308,5 @@ def build(self):
280308
self.__requested_checks,
281309
self.__requested_tasks,
282310
self.__required_documents,
311+
self.__block_biometric_consent,
283312
)

yoti_python_sdk/doc_scan/session/retrieve/get_session_result.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from iso8601 import (
5+
ParseError,
6+
iso8601,
7+
)
8+
49
from yoti_python_sdk.doc_scan import constants
510
from .check_response import AuthenticityCheckResponse
611
from .check_response import CheckResponse
@@ -29,10 +34,32 @@ def __init__(self, data):
2934
self.__state = data.get("state", None)
3035
self.__client_session_token = data.get("client_session_token", None)
3136
self.__checks = [self.__parse_check(check) for check in data.get("checks", [])]
37+
self.__biometric_consent_timestamp = self.__parse_date(
38+
data.get("biometric_consent", None)
39+
)
3240

3341
resources = data.get("resources", None)
3442
self.__resources = ResourceContainer(resources) or None
3543

44+
@staticmethod
45+
def __parse_date(date):
46+
"""
47+
Attempts to parse a date from string using the
48+
iso8601 library. Returns None if there was an error
49+
50+
:param date: the datestring to parse
51+
:type date: str
52+
:return: the parsed date
53+
:rtype: datetime.datetime or None
54+
"""
55+
if date is None:
56+
return date
57+
58+
try:
59+
return iso8601.parse_date(date)
60+
except ParseError:
61+
return None
62+
3663
@staticmethod
3764
def __parse_check(check):
3865
"""
@@ -184,3 +211,13 @@ def resources(self):
184211
:rtype: ResourceContainer or None
185212
"""
186213
return self.__resources
214+
215+
@property
216+
def biometric_consent_timestamp(self):
217+
"""
218+
The biometric constent timestamp
219+
220+
:return: the biometric constent timestamp
221+
:rtype: datetime.datetime or None
222+
"""
223+
return self.__biometric_consent_timestamp

yoti_python_sdk/tests/doc_scan/session/create/test_session_spec.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ def test_should_default_empty_arrays(self):
104104
assert len(result.requested_tasks) == 0
105105
assert len(result.required_documents) == 0
106106

107+
def test_should_build_correctly_with_block_biometric_consent_true(self):
108+
result = SessionSpecBuilder().with_block_biometric_consent(True).build()
109+
110+
assert result.block_biometric_consent is True
111+
112+
def test_should_build_correctly_with_block_biometric_consent_false(self):
113+
result = SessionSpecBuilder().with_block_biometric_consent(False).build()
114+
115+
assert result.block_biometric_consent is False
116+
117+
def test_should_build_correctly_without_block_biometric_consent_false(self):
118+
result = SessionSpecBuilder().build()
119+
120+
assert result.block_biometric_consent is None
121+
107122

108123
if __name__ == "__main__":
109124
unittest.main()

yoti_python_sdk/tests/doc_scan/session/retrieve/test_get_session_result.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import unittest
22

3+
from datetime import datetime
4+
5+
import pytz
6+
37
from yoti_python_sdk.doc_scan.session.retrieve.check_response import (
48
AuthenticityCheckResponse,
59
)
@@ -29,6 +33,7 @@ class GetSessionResultTest(unittest.TestCase):
2933
SOME_USER_TRACKING_ID = "someUserTrackingId"
3034
SOME_STATE = "someState"
3135
SOME_CLIENT_SESSION_TOKEN = "someClientSessionToken"
36+
SOME_BIOMETRIC_CONSENT = "2019-05-01T05:01:48.000Z"
3237
SOME_CHECKS = [
3338
{"type": "ID_DOCUMENT_AUTHENTICITY"},
3439
{"type": "ID_DOCUMENT_TEXT_DATA_CHECK"},
@@ -37,6 +42,17 @@ class GetSessionResultTest(unittest.TestCase):
3742
{"type": "ID_DOCUMENT_COMPARISON"},
3843
]
3944

45+
EXPECTED_BIOMETRIC_CONSENT_DATETIME = datetime(
46+
year=2019,
47+
month=5,
48+
day=1,
49+
hour=5,
50+
minute=1,
51+
second=48,
52+
microsecond=0,
53+
tzinfo=pytz.utc,
54+
)
55+
4056
def test_should_parse_different_checks(self):
4157
data = {
4258
"client_session_token_ttl": self.SOME_CLIENT_SESSION_TOKEN_TTL,
@@ -46,6 +62,7 @@ def test_should_parse_different_checks(self):
4662
"user_tracking_id": self.SOME_USER_TRACKING_ID,
4763
"checks": self.SOME_CHECKS,
4864
"resources": {},
65+
"biometric_consent": self.SOME_BIOMETRIC_CONSENT,
4966
}
5067

5168
result = GetSessionResult(data)
@@ -65,6 +82,12 @@ def test_should_parse_different_checks(self):
6582

6683
assert isinstance(result.resources, ResourceContainer)
6784

85+
assert isinstance(result.biometric_consent_timestamp, datetime)
86+
assert (
87+
result.biometric_consent_timestamp
88+
== self.EXPECTED_BIOMETRIC_CONSENT_DATETIME
89+
)
90+
6891
def test_should_filter_checks(self):
6992
data = {"checks": self.SOME_CHECKS}
7093

0 commit comments

Comments
 (0)