Skip to content

Commit 435f0ea

Browse files
committed
SDK-492: Tidy up after PR comments: remove unneccesary .items, change age_verified to not fail on non-parse, remove comment
1 parent 0e772ac commit 435f0ea

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

examples/yoti_example_django/yoti_example/templates/profile.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ <h3>Yoti Profile</h3>
271271
<td colspan="3">
272272
<table class="table">
273273
<tbody>
274-
{% for source in profile.gender.sources.items %}
274+
{% for source in profile.gender.sources %}
275275
<tr class="row no-gutters">
276276
<td class="col-md-3">Source</td>
277277
<td class="col-md-6">{{ source.value }}</td>

examples/yoti_example_flask/templates/profile.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ <h3>Yoti Profile</h3>
271271
<td colspan="3">
272272
<table class="table">
273273
<tbody>
274-
{% for source in profile.gender.sources.items %}
274+
{% for source in profile.gender.sources %}
275275
<tr class="row no-gutters">
276276
<td class="col-md-3">Source</td>
277277
<td class="col-md-6">{{ source.value }}</td>

yoti_python_sdk/activity_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def try_parse_age_verified_field(self, field):
5959
self.user_profile[config.ATTRIBUTE_IS_AGE_VERIFIED] = False
6060
return
6161

62-
raise TypeError("age_verified_field unable to be parsed")
62+
print("age_verified_field value: '{0}' was unable to be parsed into a boolean value".format(is_age_verified))
6363

6464
def try_convert_structured_postal_address_to_dict(self, field):
6565
decoder = json.JSONDecoder(object_pairs_hook=collections.OrderedDict, strict=False)

yoti_python_sdk/profile.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ def __init__(self, profile_attributes):
2222
anchors = Anchor().parse_anchors(field.anchors)
2323

2424
self.profile[field.name] = Attribute(field.name, value, anchors)
25-
# self.profile[field.name] = Attribute(field.name, field.value, anchors)
2625

2726
if field.name.startswith(config.ATTRIBUTE_AGE_OVER) or field.name.startswith(
2827
config.ATTRIBUTE_AGE_UNDER):
2928
self.try_parse_age_verified_field(field, anchors)
30-
31-
if field.name == config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS:
29+
elif field.name == config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS:
3230
self.try_convert_structured_postal_address_to_dict(field, anchors)
3331

3432
self.ensure_postal_address(anchors)
@@ -100,9 +98,7 @@ def try_parse_age_verified_field(self, field, anchors):
10098

10199
def try_convert_structured_postal_address_to_dict(self, field, anchors):
102100
decoder = json.JSONDecoder(object_pairs_hook=collections.OrderedDict, strict=False)
103-
value_to_decode = field.value
104-
if not isinstance(value_to_decode, str):
105-
value_to_decode = value_to_decode.decode()
101+
value_to_decode = field.value.decode()
106102

107103
self.profile[config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS] = Attribute(
108104
config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS,

yoti_python_sdk/tests/test_activity_details.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ def test_try_parse_selfie_field_valid_selfie():
9494
assert activity_details.base64_selfie_uri is not None
9595

9696

97-
def test_try_parse_age_verified_both_missing_returns_null():
97+
def test_try_parse_age_verified_both_missing_not_parsed():
9898
activity_details = ActivityDetails(successful_receipt())
9999
field = None
100100

101-
with pytest.raises(TypeError):
102-
ActivityDetails.try_parse_age_verified_field(activity_details, field)
101+
ActivityDetails.try_parse_age_verified_field(activity_details, field)
102+
assert not isinstance(activity_details.user_profile.get(config.ATTRIBUTE_IS_AGE_VERIFIED), bool)
103103

104104

105105
def test_try_parse_age_verified_field_age_over():
@@ -118,12 +118,12 @@ def test_try_parse_age_verified_field_age_under():
118118
assert activity_details.user_profile[config.ATTRIBUTE_IS_AGE_VERIFIED] is False
119119

120120

121-
def test_try_parse_age_verified_field_non_bool_value_throws_error():
121+
def test_try_parse_age_verified_field_non_bool_value_not_parsed():
122122
activity_details = ActivityDetails(successful_receipt())
123123
create_age_verified_field(activity_details, True, "18".encode(), 18)
124124

125-
with pytest.raises(TypeError):
126-
ActivityDetails.try_parse_age_verified_field(activity_details, activity_details.field)
125+
ActivityDetails.try_parse_age_verified_field(activity_details, activity_details.field)
126+
assert not isinstance(activity_details.user_profile.get(config.ATTRIBUTE_IS_AGE_VERIFIED), bool)
127127

128128

129129
def test_try_parse_structured_postal_address_uk():

yoti_python_sdk/tests/test_profile.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_try_parse_structured_postal_address_uk():
134134
COUNTRY_KEY: COUNTRY_VALUE,
135135
config.KEY_FORMATTED_ADDRESS: FORMATTED_ADDRESS_VALUE}
136136

137-
structured_postal_address_json = json.dumps(structured_postal_address)
137+
structured_postal_address_json = json.dumps(structured_postal_address).encode()
138138

139139
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_json))
140140

@@ -167,9 +167,9 @@ def test_try_parse_structured_postal_address_india():
167167
COUNTRY_KEY: INDIA_COUNTRY_VALUE,
168168
config.KEY_FORMATTED_ADDRESS: INDIA_FORMATTED_ADDRESS_VALUE}
169169

170-
structured_postal_address_json = json.dumps(structured_postal_address)
170+
structured_postal_address_bytes = json.dumps(structured_postal_address).encode()
171171

172-
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_json))
172+
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_bytes))
173173

174174
actual_structured_postal_address_profile = profile.profile[
175175
config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS].value
@@ -200,9 +200,9 @@ def test_try_parse_structured_postal_address_usa():
200200
COUNTRY_KEY: USA_COUNTRY_VALUE,
201201
config.KEY_FORMATTED_ADDRESS: USA_FORMATTED_ADDRESS_VALUE}
202202

203-
structured_postal_address_json = json.dumps(structured_postal_address)
203+
structured_postal_address_bytes = json.dumps(structured_postal_address).encode()
204204

205-
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_json))
205+
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_bytes))
206206

207207
actual_structured_postal_address_profile = profile.profile[
208208
config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS].value
@@ -239,9 +239,9 @@ def test_try_parse_structured_postal_address_nested_json():
239239
COUNTRY_KEY: COUNTRY_VALUE,
240240
config.KEY_FORMATTED_ADDRESS: formatted_address_json}
241241

242-
structured_postal_address_json = json.dumps(structured_postal_address)
242+
structured_postal_address_bytes = json.dumps(structured_postal_address).encode()
243243

244-
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_json))
244+
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_bytes))
245245

246246
actual_structured_postal_address_profile = profile.profile[
247247
config.ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS].value
@@ -260,9 +260,9 @@ def test_try_parse_structured_postal_address_nested_json():
260260

261261
def test_set_address_to_be_formatted_address():
262262
structured_postal_address = {config.KEY_FORMATTED_ADDRESS: FORMATTED_ADDRESS_VALUE}
263-
structured_postal_address_json = json.dumps(structured_postal_address)
263+
structured_postal_address_bytes = json.dumps(structured_postal_address).encode()
264264

265-
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_json))
265+
profile = Profile(create_attribute_list_with_structured_postal_address_field(structured_postal_address_bytes))
266266

267267
assert profile.profile[config.ATTRIBUTE_POSTAL_ADDRESS].value == FORMATTED_ADDRESS_VALUE
268268

0 commit comments

Comments
 (0)