Skip to content

Commit 0a8a5fc

Browse files
committed
SDK-1732: Allow manual check to be configured on authenticity checks
1 parent 9c4b915 commit 0a8a5fc

File tree

3 files changed

+88
-8
lines changed

3 files changed

+88
-8
lines changed

examples/doc_scan/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def create_session():
5050
.with_client_session_token_ttl(600)
5151
.with_resources_ttl(90000)
5252
.with_user_tracking_id("some-user-tracking-id")
53-
.with_requested_check(RequestedDocumentAuthenticityCheckBuilder().build())
53+
.with_requested_check(
54+
RequestedDocumentAuthenticityCheckBuilder()
55+
.with_manual_check_never()
56+
.build()
57+
)
5458
.with_requested_check(
5559
RequestedLivenessCheckBuilder()
5660
.for_zoom_liveness()

yoti_python_sdk/doc_scan/session/create/check/document_authenticity.py

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

4-
from yoti_python_sdk.doc_scan.constants import ID_DOCUMENT_AUTHENTICITY
4+
from yoti_python_sdk.doc_scan import constants
55
from yoti_python_sdk.utils import YotiSerializable, remove_null_values
66
from .requested_check import RequestedCheck
77

@@ -11,8 +11,26 @@ class RequestedDocumentAuthenticityCheckConfig(YotiSerializable):
1111
The configuration applied when creating a Document Authenticity Check
1212
"""
1313

14+
def __init__(self, manual_check=None):
15+
"""
16+
:param manual_check: the manual check value
17+
:type manual_check: str
18+
"""
19+
self.__manual_check = manual_check
20+
21+
@property
22+
def manual_check(self):
23+
"""
24+
Returns a value for a manual check for a given
25+
Authenticity Check
26+
27+
:return: the manual check value
28+
:rtype: str
29+
"""
30+
return self.__manual_check
31+
1432
def to_json(self):
15-
return remove_null_values({})
33+
return remove_null_values({"manual_check": self.manual_check})
1634

1735

1836
class RequestedDocumentAuthenticityCheck(RequestedCheck):
@@ -29,19 +47,50 @@ def __init__(self, config):
2947

3048
@property
3149
def type(self):
32-
return ID_DOCUMENT_AUTHENTICITY
50+
return constants.ID_DOCUMENT_AUTHENTICITY
3351

3452
@property
3553
def config(self):
3654
return self.__config
3755

3856

39-
class RequestedDocumentAuthenticityCheckBuilder(object):
57+
class RequestedDocumentAuthenticityCheckBuilder:
4058
"""
4159
Builder to assist creation of :class:`RequestedDocumentAuthenticityCheck`
4260
"""
4361

44-
@staticmethod
45-
def build():
46-
config = RequestedDocumentAuthenticityCheckConfig()
62+
def __init__(self):
63+
self.__manual_check = None
64+
65+
def with_manual_check_always(self):
66+
"""
67+
:return: the builder
68+
:rtype: RequestedDocumentAuthenticityCheckBuilder
69+
"""
70+
self.__manual_check = constants.ALWAYS
71+
return self
72+
73+
def with_manual_check_fallback(self):
74+
"""
75+
:return: the builder
76+
:rtype: RequestedDocumentAuthenticityCheckBuilder
77+
"""
78+
self.__manual_check = constants.FALLBACK
79+
return self
80+
81+
def with_manual_check_never(self):
82+
"""
83+
:return: the builder
84+
:rtype: RequestedDocumentAuthenticityCheckBuilder
85+
"""
86+
self.__manual_check = constants.NEVER
87+
return self
88+
89+
def build(self=None):
90+
if self is None:
91+
manual_check = None
92+
else:
93+
manual_check = self.__manual_check
94+
95+
config = RequestedDocumentAuthenticityCheckConfig(manual_check)
4796
return RequestedDocumentAuthenticityCheck(config)

yoti_python_sdk/tests/doc_scan/session/create/check/test_requested_document_authenticity_check.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ def test_should_serialize_to_json_without_error(self):
2929
s = json.dumps(result, cls=YotiEncoder)
3030
assert s is not None and s != ""
3131

32+
def test_should_build_with_manual_check_always(self):
33+
result = (
34+
RequestedDocumentAuthenticityCheckBuilder()
35+
.with_manual_check_always()
36+
.build()
37+
)
38+
39+
assert result.config.manual_check == "ALWAYS"
40+
41+
def test_should_build_with_manual_check_fallback(self):
42+
result = (
43+
RequestedDocumentAuthenticityCheckBuilder()
44+
.with_manual_check_fallback()
45+
.build()
46+
)
47+
48+
assert result.config.manual_check == "FALLBACK"
49+
50+
def test_should_build_with_manual_check_never(self):
51+
result = (
52+
RequestedDocumentAuthenticityCheckBuilder()
53+
.with_manual_check_never()
54+
.build()
55+
)
56+
57+
assert result.config.manual_check == "NEVER"
58+
3259

3360
if __name__ == "__main__":
3461
unittest.main()

0 commit comments

Comments
 (0)