Skip to content

Commit 9af34b3

Browse files
Merge pull request #347 from getyoti/feat/non_latin_documents
SDK-2027: adding non-latin support for session and supported documents
2 parents e3be90a + fad2ce8 commit 9af34b3

File tree

6 files changed

+108
-3
lines changed

6 files changed

+108
-3
lines changed

yoti_python_sdk/doc_scan/session/create/filter/orthogonal_restrictions_filter.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ def to_json(self):
6868

6969

7070
class OrthogonalRestrictionsFilter(DocumentFilter):
71-
def __init__(self, country_restriction, type_restriction):
71+
def __init__(self, country_restriction, type_restriction, allow_non_latin_documents=None):
7272
DocumentFilter.__init__(self, filter_type=ORTHOGONAL_RESTRICTIONS)
7373

7474
self.__country_restriction = country_restriction
7575
self.__type_restriction = type_restriction
76+
self.__allow_non_latin_documents = allow_non_latin_documents
7677

7778
@property
7879
def country_restriction(self):
@@ -94,10 +95,23 @@ def type_restriction(self):
9495
"""
9596
return self.__type_restriction
9697

98+
@property
99+
def allow_non_latin_documents(self):
100+
"""
101+
Returns the flag for whether non-latin documents are allowed.
102+
103+
:return: allow_non_latin_documents
104+
:rtype: bool
105+
"""
106+
return self.__allow_non_latin_documents
107+
97108
def to_json(self):
98109
parent = DocumentFilter.to_json(self)
99110
parent["country_restriction"] = self.country_restriction
100111
parent["type_restriction"] = self.type_restriction
112+
if self.__allow_non_latin_documents is not None:
113+
parent["allow_non_latin_documents"] = self.__allow_non_latin_documents
114+
101115
return remove_null_values(parent)
102116

103117

@@ -117,6 +131,7 @@ class OrthogonalRestrictionsFilterBuilder(object):
117131
def __init__(self):
118132
self.__country_restriction = None
119133
self.__type_restriction = None
134+
self.__allow_non_latin_documents = None
120135

121136
def with_whitelisted_country_codes(self, country_codes):
122137
"""
@@ -170,6 +185,26 @@ def with_blacklisted_document_types(self, document_types):
170185
self.__type_restriction = TypeRestriction(INCLUSION_BLACKLIST, document_types)
171186
return self
172187

188+
def allow_non_latin_documents(self):
189+
"""
190+
Sets a True value for "allow non-latin documents" flag.
191+
192+
:return: the builder
193+
:rtype: OrthogonalRestrictionsFilterBuilder
194+
"""
195+
self.__allow_non_latin_documents = True
196+
return self
197+
198+
def disable_non_latin_documents(self):
199+
"""
200+
Sets a False value for "allow non-latin documents" flag.
201+
202+
:return: the builder
203+
:rtype: OrthogonalRestrictionsFilterBuilder
204+
"""
205+
self.__allow_non_latin_documents = False
206+
return self
207+
173208
def build(self):
174209
"""
175210
Builds the orthogonal filter, using the supplied whitelisted/blacklisted values
@@ -178,5 +213,5 @@ def build(self):
178213
:rtype: OrthogonalRestrictionsFilter
179214
"""
180215
return OrthogonalRestrictionsFilter(
181-
self.__country_restriction, self.__type_restriction
216+
self.__country_restriction, self.__type_restriction, self.__allow_non_latin_documents
182217
)

yoti_python_sdk/doc_scan/support/supported_documents.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ def __init__(self, data=None):
44
data = dict()
55

66
self.__type = data.get("type", None)
7+
self.__is_strictly_latin = data.get("is_strictly_latin", None)
78

89
@property
910
def type(self):
1011
return self.__type
1112

13+
@property
14+
def is_strictly_latin(self):
15+
return self.__is_strictly_latin
16+
1217

1318
class SupportedCountry(object):
1419
def __init__(self, data=None):

yoti_python_sdk/dynamic_sharing_service/policy/source_constraint_builder.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class SourceConstraintBuilder(object):
1515
def __init__(self):
1616
self.__soft_preference = False
1717
self.__anchors = []
18+
self.__is_strictly_latin = None
1819

1920
def with_soft_preference(self, value=True):
2021
"""
@@ -64,14 +65,27 @@ def with_driving_licence(self, subtype=""):
6465
"""
6566
return self.with_anchor_by_name(ANCHOR_VALUE_DRIVING_LICENCE, subtype)
6667

68+
def allow_strictly_latin(self):
69+
self.__is_strictly_latin = True
70+
return self
71+
72+
def disable_strictly_latin(self):
73+
self.__is_strictly_latin = False
74+
return self
75+
6776
def build(self):
6877
"""
6978
:returns: A dict describing the source constraint
7079
"""
71-
return {
80+
constrain = {
7281
"type": "SOURCE",
7382
"preferred_sources": {
7483
"soft_preference": self.__soft_preference,
7584
"anchors": self.__anchors,
7685
},
7786
}
87+
88+
if self.__is_strictly_latin is not None:
89+
constrain["is_strictly_latin"] = self.__is_strictly_latin
90+
91+
return constrain

yoti_python_sdk/tests/doc_scan/session/create/subcheck/test_issuing_authority_sub_check.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ def test_should_always_build_with_requested_as_boolean_true(self):
2929

3030
assert issuing_authority_sub_check.requested is True
3131

32+
def test_allow_non_latin_documents_set_to_true(self):
33+
filter = OrthogonalRestrictionsFilterBuilder().allow_non_latin_documents().build()
34+
35+
assert filter.allow_non_latin_documents is True
36+
37+
def test_allow_non_latin_documents_set_to_false(self):
38+
filter = OrthogonalRestrictionsFilterBuilder().disable_non_latin_documents().build()
39+
40+
assert filter.allow_non_latin_documents is False
41+
42+
def test_default_non_latin_documents(self):
43+
filter = OrthogonalRestrictionsFilterBuilder().build()
44+
45+
assert 'allow_non_latin_documents' not in filter.to_json()
46+
3247
def test_build_invalid_filter(self):
3348
filter = 'invalid'
3449

yoti_python_sdk/tests/doc_scan/support/test_supported_documents.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ def test_supported_document_should_not_throw_exception_on_missing_data():
1818
assert result.type is None
1919

2020

21+
def test_supported_document_created_with_is_strictly_latin_as_true():
22+
result = SupportedDocument({"is_strictly_latin": True})
23+
24+
assert result.is_strictly_latin is True
25+
26+
27+
def test_supported_document_created_with_is_strictly_latin_as_false():
28+
result = SupportedDocument({"is_strictly_latin": False})
29+
30+
assert result.is_strictly_latin is False
31+
32+
33+
def test_supported_document_created_without_is_strictly_latin():
34+
result = SupportedDocument({"type": "someSupportedDocument"})
35+
36+
assert result.is_strictly_latin is None
37+
38+
2139
def test_supported_country_should_parse_data():
2240
data = {
2341
"code": "someCode",

yoti_python_sdk/tests/dynamic_sharing_service/policy/test_source_constraint_builder.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,21 @@ def test_with_soft_preference():
3333
assert ANCHOR_VALUE_DRIVING_LICENCE in [a["name"] for a in anchors]
3434
assert ANCHOR_VALUE_PASSPORT in [a["name"] for a in anchors]
3535
assert constraint["preferred_sources"]["soft_preference"]
36+
37+
38+
def test_with_is_strictly_latin_set_true():
39+
constraint = SourceConstraintBuilder().allow_strictly_latin().build()
40+
41+
assert constraint["is_strictly_latin"] is True
42+
43+
44+
def test_with_is_strictly_latin_set_false():
45+
constraint = SourceConstraintBuilder().disable_strictly_latin().build()
46+
47+
assert constraint["is_strictly_latin"] is False
48+
49+
50+
def test_with_is_strictly_latin_default():
51+
constraint = SourceConstraintBuilder().build()
52+
53+
assert "is_strictly_latin" not in constraint

0 commit comments

Comments
 (0)