2
2
3
3
from datetime import datetime
4
4
from types import SimpleNamespace
5
+ import os .path
5
6
6
7
from yoti_python_sdk .share .extra_data import ExtraData
8
+ from yoti_python_sdk .tests import file_helper
9
+ from yoti_python_sdk .protobuf import protobuf
10
+
11
+ FIXTURES_DIR = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "fixtures" )
12
+ EXTRADATA = os .path .join (FIXTURES_DIR , "testextradata.txt" )
7
13
8
14
9
15
def create_third_party_test_data (token_value , expiry_date , * definitions ):
@@ -17,14 +23,20 @@ def create_third_party_test_data(token_value, expiry_date, *definitions):
17
23
return SimpleNamespace (type = ExtraData .THIRD_PARTY_ATTRIBUTE , value = attribute )
18
24
19
25
26
+ def get_extra_data_from_base64 (filepath ):
27
+ extra_data_bytes = file_helper .get_file_bytes (filepath )
28
+ protobuf_extra_data = protobuf .Protobuf .extra_data (extra_data_bytes )
29
+ return ExtraData (protobuf_extra_data .list )
30
+
31
+
20
32
def test_attribute_issuance_details_should_return_nil_when_no_data_entries ():
21
33
extra_data = ExtraData ([])
22
34
23
35
assert extra_data .attribute_issuance_details is None
24
36
25
37
26
38
def test_should_return_first_matching_third_party_attribute ():
27
- expiry_date = datetime .now ()
39
+ expiry_date = datetime .now (). isoformat ()
28
40
29
41
thirdparty_attribute1 = create_third_party_test_data (
30
42
"tokenValue1" , expiry_date , "attributeName1"
@@ -41,3 +53,14 @@ def test_should_return_first_matching_third_party_attribute():
41
53
== "attributeName1"
42
54
)
43
55
assert parsed_extra_data .attribute_issuance_details .expiry_date == expiry_date
56
+
57
+
58
+ def test_should_parse_multiple_issuing_attributes ():
59
+ extra_data = get_extra_data_from_base64 (EXTRADATA )
60
+ result = extra_data .attribute_issuance_details
61
+ assert result is not None
62
+
63
+ assert result .token == "someIssuanceToken"
64
+ assert result .expiry_date == "2019-10-15T22:04:05.123Z"
65
+ assert result .attributes [0 ].name == "com.thirdparty.id"
66
+ assert result .attributes [1 ].name == "com.thirdparty.other_id"
0 commit comments