Skip to content

Commit 7e02051

Browse files
Copilotmehmet-yoti
andcommitted
Add enforce_handoff property to SdkConfig with tests
Co-authored-by: mehmet-yoti <[email protected]>
1 parent c70374d commit 7e02051

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

yoti_python_sdk/doc_scan/session/create/sdk_config.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(
2323
error_url,
2424
allow_handoff=None,
2525
privacy_policy_url=None,
26+
enforce_handoff=None,
2627
):
2728
"""
2829
:param allowed_capture_methods: the allowed capture methods
@@ -45,6 +46,8 @@ def __init__(
4546
:type privacy_policy_url: str
4647
:param allow_handoff: boolean flag for allow_handoff
4748
:type allow_handoff: bool
49+
:param enforce_handoff: boolean flag for enforce_handoff
50+
:type enforce_handoff: bool
4851
"""
4952
self.__allowed_capture_methods = allowed_capture_methods
5053
self.__primary_colour = primary_colour
@@ -56,6 +59,7 @@ def __init__(
5659
self.__error_url = error_url
5760
self.__privacy_policy_url = privacy_policy_url
5861
self.__allow_handoff = allow_handoff
62+
self.__enforce_handoff = enforce_handoff
5963

6064
@property
6165
def allowed_capture_methods(self):
@@ -148,6 +152,16 @@ def allow_handoff(self):
148152
"""
149153
return self.__allow_handoff
150154

155+
@property
156+
def enforce_handoff(self):
157+
"""
158+
Flag to enforce handoff when allow_handoff is enabled.
159+
Cannot be true if allow_handoff is false.
160+
161+
:return: the enforce_handoff
162+
"""
163+
return self.__enforce_handoff
164+
151165
def to_json(self):
152166
return remove_null_values(
153167
{
@@ -161,6 +175,7 @@ def to_json(self):
161175
"error_url": self.error_url,
162176
"privacy_policy_url": self.privacy_policy_url,
163177
"allow_handoff": self.allow_handoff,
178+
"enforce_handoff": self.enforce_handoff,
164179
}
165180
)
166181

@@ -181,6 +196,7 @@ def __init__(self):
181196
self.__error_url = None
182197
self.__privacy_policy_url = None
183198
self.__allow_handoff = None
199+
self.__enforce_handoff = None
184200

185201
def with_allowed_capture_methods(self, allowed_capture_methods):
186202
"""
@@ -320,6 +336,18 @@ def with_allow_handoff(self, flag):
320336
self.__allow_handoff = flag
321337
return self
322338

339+
def with_enforce_handoff(self, flag):
340+
"""
341+
Sets the enforce handoff flag
342+
343+
:param flag: boolean value for flag
344+
:type flag: bool
345+
:return: the builder
346+
:rtype: SdkConfigBuilder
347+
"""
348+
self.__enforce_handoff = flag
349+
return self
350+
323351
def build(self):
324352
return SdkConfig(
325353
self.__allowed_capture_methods,
@@ -332,4 +360,5 @@ def build(self):
332360
self.__error_url,
333361
self.__allow_handoff,
334362
self.__privacy_policy_url,
363+
self.__enforce_handoff,
335364
)

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SdkConfigTest(unittest.TestCase):
1616
SOME_ERROR_URL = "https://mysite.com/yoti/error"
1717
SOME_PRIVACY_POLICY_URL = "https://mysite.com/privacy"
1818
SOME_ALLOW_HANDOFF = True
19+
SOME_ENFORCE_HANDOFF = True
1920

2021
def test_should_build_correctly(self):
2122
result = (
@@ -30,6 +31,7 @@ def test_should_build_correctly(self):
3031
.with_error_url(self.SOME_ERROR_URL)
3132
.with_privacy_policy_url(self.SOME_PRIVACY_POLICY_URL)
3233
.with_allow_handoff(self.SOME_ALLOW_HANDOFF)
34+
.with_enforce_handoff(self.SOME_ENFORCE_HANDOFF)
3335
.build()
3436
)
3537

@@ -44,6 +46,7 @@ def test_should_build_correctly(self):
4446
assert result.error_url is self.SOME_ERROR_URL
4547
assert result.privacy_policy_url is self.SOME_PRIVACY_POLICY_URL
4648
assert result.allow_handoff is True
49+
assert result.enforce_handoff is True
4750

4851
def test_should_allows_camera(self):
4952
result = SdkConfigBuilder().with_allows_camera().build()
@@ -60,6 +63,45 @@ def test_passing_allow_handoff_false_value(self):
6063

6164
assert result.allow_handoff is False
6265

66+
def test_not_passing_enforce_handoff(self):
67+
result = SdkConfigBuilder().with_allows_camera().build()
68+
69+
assert result.enforce_handoff is None
70+
71+
def test_passing_enforce_handoff_true_value(self):
72+
result = SdkConfigBuilder().with_enforce_handoff(True).build()
73+
74+
assert result.enforce_handoff is True
75+
76+
def test_passing_enforce_handoff_false_value(self):
77+
result = SdkConfigBuilder().with_enforce_handoff(False).build()
78+
79+
assert result.enforce_handoff is False
80+
81+
def test_enforce_handoff_with_allow_handoff_both_true(self):
82+
result = (
83+
SdkConfigBuilder()
84+
.with_allow_handoff(True)
85+
.with_enforce_handoff(True)
86+
.build()
87+
)
88+
89+
assert result.allow_handoff is True
90+
assert result.enforce_handoff is True
91+
92+
def test_enforce_handoff_serializes_to_json(self):
93+
result = (
94+
SdkConfigBuilder()
95+
.with_allows_camera()
96+
.with_allow_handoff(True)
97+
.with_enforce_handoff(True)
98+
.build()
99+
)
100+
101+
json_data = result.to_json()
102+
assert json_data["allow_handoff"] is True
103+
assert json_data["enforce_handoff"] is True
104+
63105
def test_should_serialize_to_json_without_error(self):
64106
result = (
65107
SdkConfigBuilder()

0 commit comments

Comments
 (0)