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,
suppressed_screens=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 suppressed_screens: list of screen identifiers to suppress in the flow
:type suppressed_screens: list[str] or None
"""
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.__suppressed_screens = suppressed_screens

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

@property
def suppressed_screens(self):
"""
List of screen identifiers to suppress in the flow.

:return: the suppressed screens
:rtype: list[str] or None
"""
return self.__suppressed_screens

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,
"suppressed_screens": self.suppressed_screens,
}
)

Expand All @@ -181,6 +196,7 @@ def __init__(self):
self.__error_url = None
self.__privacy_policy_url = None
self.__allow_handoff = None
self.__suppressed_screens = 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_suppressed_screens(self, suppressed_screens):
"""
Sets the list of screen identifiers to suppress in the flow

:param suppressed_screens: list of screen identifiers
:type suppressed_screens: list[str]
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__suppressed_screens = suppressed_screens
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.__suppressed_screens,
)
40 changes: 40 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_SUPPRESSED_SCREENS = ["screen1", "screen2", "screen3"]

def test_should_build_correctly(self):
result = (
Expand Down Expand Up @@ -78,6 +79,45 @@ def test_should_serialize_to_json_without_error(self):
s = json.dumps(result, cls=YotiEncoder)
assert s is not None and s != ""

def test_should_build_with_suppressed_screens(self):
result = (
SdkConfigBuilder()
.with_allows_camera()
.with_suppressed_screens(self.SOME_SUPPRESSED_SCREENS)
.build()
)

assert isinstance(result, SdkConfig)
assert result.suppressed_screens == self.SOME_SUPPRESSED_SCREENS
assert len(result.suppressed_screens) == 3

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

assert result.suppressed_screens is None

def test_passing_empty_suppressed_screens_list(self):
result = SdkConfigBuilder().with_suppressed_screens([]).build()

assert result.suppressed_screens == []

def test_should_serialize_to_json_with_suppressed_screens(self):
result = (
SdkConfigBuilder()
.with_allows_camera_and_upload()
.with_primary_colour(self.SOME_PRIMARY_COLOUR)
.with_suppressed_screens(self.SOME_SUPPRESSED_SCREENS)
.build()
)

s = json.dumps(result, cls=YotiEncoder)
assert s is not None and s != ""

# Verify suppressed_screens is in the JSON
parsed = json.loads(s)
assert "suppressed_screens" in parsed
assert parsed["suppressed_screens"] == self.SOME_SUPPRESSED_SCREENS


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