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
28 changes: 28 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,
brand_id=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 brand_id: the brand identifier for custom branding
:type brand_id: str
"""
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.__brand_id = brand_id

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

@property
def brand_id(self):
"""
The brand identifier for custom branding

:return: the brand_id
"""
return self.__brand_id

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

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

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

def with_brand_id(self, brand_id):
"""
Sets the brand identifier for custom branding

:param brand_id: the brand identifier
:type brand_id: str
:return: the builder
:rtype: SdkConfigBuilder
"""
self.__brand_id = brand_id
return self

def build(self):
return SdkConfig(
self.__allowed_capture_methods,
Expand All @@ -332,4 +359,5 @@ def build(self):
self.__error_url,
self.__allow_handoff,
self.__privacy_policy_url,
self.__brand_id,
)
35 changes: 35 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_BRAND_ID = "my-custom-brand"

def test_should_build_correctly(self):
result = (
Expand Down Expand Up @@ -78,6 +79,40 @@ 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_brand_id(self):
result = (
SdkConfigBuilder()
.with_allows_camera_and_upload()
.with_brand_id(self.SOME_BRAND_ID)
.build()
)

assert isinstance(result, SdkConfig)
assert result.brand_id == self.SOME_BRAND_ID

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

assert result.brand_id is None

def test_should_serialize_brand_id_to_json(self):
result = (
SdkConfigBuilder()
.with_allows_camera_and_upload()
.with_brand_id(self.SOME_BRAND_ID)
.build()
)

json_data = json.loads(json.dumps(result, cls=YotiEncoder))
assert "brand_id" in json_data
assert json_data["brand_id"] == self.SOME_BRAND_ID

def test_should_not_include_brand_id_in_json_when_not_set(self):
result = SdkConfigBuilder().with_allows_camera_and_upload().build()

json_data = json.loads(json.dumps(result, cls=YotiEncoder))
assert "brand_id" not in json_data


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