-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from getyoti/SDK-282-IsAgeVerifiedHelper
[SDK-282]: Added IsAgeVerified helper
- Loading branch information
Showing
11 changed files
with
128 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
SDK_IDENTIFIER = "Python" | ||
ATTRIBUTE_AGE_OVER = "age_over:" | ||
ATTRIBUTE_AGE_UNDER = "age_under:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
import pytest | ||
|
||
from yoti_python_sdk.activity_details import ActivityDetails | ||
from yoti_python_sdk.protobuf.v1.protobuf import Protobuf | ||
from yoti_python_sdk.tests.conftest import successful_receipt | ||
|
||
|
||
def create_selfie_field(activity_details): | ||
activity_details.field = lambda: None | ||
activity_details.field.name = "selfie" | ||
activity_details.field.value = "base64(ง •̀_•́)ง" | ||
activity_details.field.content_type = Protobuf.CT_STRING | ||
|
||
|
||
def create_age_verified_field(activity_details, over, encoded_string_verified_value, age): | ||
activity_details.field = lambda: None | ||
activity_details.field.name = "age_over:{0}".format(age) if over is True else "age_under:".format(age) | ||
activity_details.field.value = encoded_string_verified_value | ||
activity_details.field.content_type = Protobuf.CT_STRING | ||
|
||
|
||
def test_try_parse_selfie_field_valid_selfie(): | ||
activity_details = ActivityDetails(successful_receipt()) | ||
create_selfie_field(activity_details) | ||
|
||
ActivityDetails.try_parse_selfie_field(activity_details, activity_details.field) | ||
assert activity_details.base64_selfie_uri is not None | ||
|
||
|
||
def test_try_parse_age_verified_both_missing_returns_null(): | ||
activity_details = ActivityDetails(successful_receipt()) | ||
create_selfie_field(activity_details) | ||
|
||
ActivityDetails.try_parse_age_verified_field(activity_details, activity_details.field) | ||
assert not activity_details.user_profile | ||
|
||
|
||
def test_try_parse_age_verified_field_age_over(): | ||
activity_details = ActivityDetails(successful_receipt()) | ||
create_age_verified_field(activity_details, True, "true".encode(), 18) | ||
|
||
ActivityDetails.try_parse_age_verified_field(activity_details, activity_details.field) | ||
assert activity_details.user_profile['is_age_verified'] is True | ||
|
||
|
||
def test_try_parse_age_verified_field_age_under(): | ||
activity_details = ActivityDetails(successful_receipt()) | ||
create_age_verified_field(activity_details, False, "false".encode(), 55) | ||
|
||
ActivityDetails.try_parse_age_verified_field(activity_details, activity_details.field) | ||
assert activity_details.user_profile['is_age_verified'] is False | ||
|
||
|
||
def test_try_parse_age_verified_field_non_bool_value_throws_error(): | ||
activity_details = ActivityDetails(successful_receipt()) | ||
create_age_verified_field(activity_details, True, "18".encode(), 18) | ||
|
||
with pytest.raises(TypeError): | ||
ActivityDetails.try_parse_age_verified_field(activity_details, activity_details.field) |