|
| 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