Skip to content
Draft
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
29 changes: 29 additions & 0 deletions yoti_python_sdk/doc_scan/session/create/sdk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(
error_url,
allow_handoff=None,
privacy_policy_url=None,
enforce_handoff=None,
):
"""
:param allowed_capture_methods: the allowed capture methods
Expand All @@ -45,6 +46,8 @@ def __init__(
:type privacy_policy_url: str
:param allow_handoff: boolean flag for allow_handoff
:type allow_handoff: bool
:param enforce_handoff: boolean flag for enforce_handoff
:type enforce_handoff: bool
"""
self.__allowed_capture_methods = allowed_capture_methods
self.__primary_colour = primary_colour
Expand All @@ -56,6 +59,7 @@ def __init__(
self.__error_url = error_url
self.__privacy_policy_url = privacy_policy_url
self.__allow_handoff = allow_handoff
self.__enforce_handoff = enforce_handoff

@property
def allowed_capture_methods(self):
Expand Down Expand Up @@ -148,6 +152,16 @@ def allow_handoff(self):
"""
return self.__allow_handoff

@property
def enforce_handoff(self):
"""
Flag to enforce handoff when allow_handoff is enabled.
Cannot be true if allow_handoff is false.

:return: the enforce_handoff
"""
return self.__enforce_handoff

def to_json(self):
return remove_null_values(
{
Expand All @@ -161,6 +175,7 @@ def to_json(self):
"error_url": self.error_url,
"privacy_policy_url": self.privacy_policy_url,
"allow_handoff": self.allow_handoff,
"enforce_handoff": self.enforce_handoff,
}
)

Expand All @@ -181,6 +196,7 @@ def __init__(self):
self.__error_url = None
self.__privacy_policy_url = None
self.__allow_handoff = None
self.__enforce_handoff = None

def with_allowed_capture_methods(self, allowed_capture_methods):
"""
Expand Down Expand Up @@ -320,6 +336,18 @@ def with_allow_handoff(self, flag):
self.__allow_handoff = flag
return self

def with_enforce_handoff(self, flag):
"""
Sets the enforce handoff flag

:param flag: boolean value for flag
:type flag: bool
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__enforce_handoff = flag
return self

def build(self):
return SdkConfig(
self.__allowed_capture_methods,
Expand All @@ -332,4 +360,5 @@ def build(self):
self.__error_url,
self.__allow_handoff,
self.__privacy_policy_url,
self.__enforce_handoff,
)
42 changes: 42 additions & 0 deletions yoti_python_sdk/tests/doc_scan/session/create/test_sdk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SdkConfigTest(unittest.TestCase):
SOME_ERROR_URL = "https://mysite.com/yoti/error"
SOME_PRIVACY_POLICY_URL = "https://mysite.com/privacy"
SOME_ALLOW_HANDOFF = True
SOME_ENFORCE_HANDOFF = True

def test_should_build_correctly(self):
result = (
Expand All @@ -30,6 +31,7 @@ def test_should_build_correctly(self):
.with_error_url(self.SOME_ERROR_URL)
.with_privacy_policy_url(self.SOME_PRIVACY_POLICY_URL)
.with_allow_handoff(self.SOME_ALLOW_HANDOFF)
.with_enforce_handoff(self.SOME_ENFORCE_HANDOFF)
.build()
)

Expand All @@ -44,6 +46,7 @@ def test_should_build_correctly(self):
assert result.error_url is self.SOME_ERROR_URL
assert result.privacy_policy_url is self.SOME_PRIVACY_POLICY_URL
assert result.allow_handoff is True
assert result.enforce_handoff is True

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

assert result.allow_handoff is False

def test_not_passing_enforce_handoff(self):
result = SdkConfigBuilder().with_allows_camera().build()

assert result.enforce_handoff is None

def test_passing_enforce_handoff_true_value(self):
result = SdkConfigBuilder().with_enforce_handoff(True).build()

assert result.enforce_handoff is True

def test_passing_enforce_handoff_false_value(self):
result = SdkConfigBuilder().with_enforce_handoff(False).build()

assert result.enforce_handoff is False

def test_enforce_handoff_with_allow_handoff_both_true(self):
result = (
SdkConfigBuilder()
.with_allow_handoff(True)
.with_enforce_handoff(True)
.build()
)

assert result.allow_handoff is True
assert result.enforce_handoff is True

def test_enforce_handoff_serializes_to_json(self):
result = (
SdkConfigBuilder()
.with_allows_camera()
.with_allow_handoff(True)
.with_enforce_handoff(True)
.build()
)

json_data = result.to_json()
assert json_data["allow_handoff"] is True
assert json_data["enforce_handoff"] is True

def test_should_serialize_to_json_without_error(self):
result = (
SdkConfigBuilder()
Expand Down