Skip to content

Commit 45aee6b

Browse files
committed
SDK-1260: Add ThirdPartyAttributeExtension
1 parent eb16429 commit 45aee6b

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
import copy
4+
5+
6+
class ThirdPartyAttributeExtension(object):
7+
THIRDPARTY_ATTRIBUTE = "THIRD_PARTY_ATTRIBUTE"
8+
9+
def __init__(self):
10+
self.__extension = {}
11+
self.__extension["type"] = self.THIRDPARTY_ATTRIBUTE
12+
self.__extension["content"] = {"expiry_date": None, "definitions": []}
13+
14+
def with_expiry_date(self, expiry_date):
15+
self.__extension["content"]["expiry_date"] = expiry_date.isoformat()
16+
return self
17+
18+
def with_definitions(self, *names):
19+
self.__extension["content"]["definitions"].extend([{"name": s} for s in names])
20+
return self
21+
22+
def build(self):
23+
return copy.deepcopy(self.__extension)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from datetime import datetime
5+
from yoti_python_sdk.dynamic_sharing_service.extension.third_party_attribute_extension import (
6+
ThirdPartyAttributeExtension,
7+
)
8+
9+
10+
def test_should_create_extension():
11+
DEFINITION = "some_value"
12+
expiry_date = datetime(2019, 10, 30, 12, 10, 9, int(458e3))
13+
14+
extension = (
15+
ThirdPartyAttributeExtension()
16+
.with_expiry_date(expiry_date)
17+
.with_definitions(DEFINITION)
18+
.build()
19+
)
20+
21+
assert extension["type"] == ThirdPartyAttributeExtension.THIRDPARTY_ATTRIBUTE
22+
assert extension["content"]["expiry_date"] == "2019-10-30T12:10:09.458000"
23+
assert extension["content"]["definitions"][0]["name"] == DEFINITION
24+
25+
26+
def test_with_definition_should_add_to_list():
27+
DEFINITION1 = "some_attribute"
28+
DEFINITION2 = "some_other_attribute"
29+
30+
expiry_date = datetime(2019, 10, 30, 12, 10, 9, int(458e3))
31+
32+
extension = (
33+
ThirdPartyAttributeExtension()
34+
.with_expiry_date(expiry_date)
35+
.with_definitions(DEFINITION1)
36+
.with_definitions(DEFINITION2)
37+
.build()
38+
)
39+
40+
assert extension["type"] == ThirdPartyAttributeExtension.THIRDPARTY_ATTRIBUTE
41+
assert extension["content"]["expiry_date"] == "2019-10-30T12:10:09.458000"
42+
43+
assert extension["content"]["definitions"][0]["name"] == DEFINITION1
44+
assert extension["content"]["definitions"][1]["name"] == DEFINITION2
45+
46+
47+
def test_with_definition_should_add_multiple():
48+
DEFINITION1 = "some_attribute"
49+
DEFINITION2 = "some_other_attribute"
50+
51+
expiry_date = datetime(2019, 10, 30, 12, 10, 9, int(458e3))
52+
53+
extension = (
54+
ThirdPartyAttributeExtension()
55+
.with_expiry_date(expiry_date)
56+
.with_definitions(DEFINITION1, DEFINITION2)
57+
.build()
58+
)
59+
60+
assert extension["type"] == ThirdPartyAttributeExtension.THIRDPARTY_ATTRIBUTE
61+
assert extension["content"]["expiry_date"] == "2019-10-30T12:10:09.458000"
62+
63+
assert extension["content"]["definitions"][0]["name"] == DEFINITION1
64+
assert extension["content"]["definitions"][1]["name"] == DEFINITION2

0 commit comments

Comments
 (0)