22from __future__ import unicode_literals
33
44from datetime import datetime
5+
6+ import pytest
7+ import pytz
8+
59from yoti_python_sdk .dynamic_sharing_service .extension .third_party_attribute_extension import (
610 ThirdPartyAttributeExtension ,
711)
@@ -19,7 +23,7 @@ def test_should_create_extension():
1923 )
2024
2125 assert extension ["type" ] == ThirdPartyAttributeExtension .THIRDPARTY_ATTRIBUTE
22- assert extension ["content" ]["expiry_date" ] == "2019-10-30T12:10:09.458000 "
26+ assert extension ["content" ]["expiry_date" ] == "2019-10-30T12:10:09.458Z "
2327 assert extension ["content" ]["definitions" ][0 ]["name" ] == DEFINITION
2428
2529
@@ -38,7 +42,7 @@ def test_with_definition_should_add_to_list():
3842 )
3943
4044 assert extension ["type" ] == ThirdPartyAttributeExtension .THIRDPARTY_ATTRIBUTE
41- assert extension ["content" ]["expiry_date" ] == "2019-10-30T12:10:09.458000 "
45+ assert extension ["content" ]["expiry_date" ] == "2019-10-30T12:10:09.458Z "
4246
4347 assert extension ["content" ]["definitions" ][0 ]["name" ] == DEFINITION1
4448 assert extension ["content" ]["definitions" ][1 ]["name" ] == DEFINITION2
@@ -58,7 +62,82 @@ def test_with_definition_should_add_multiple():
5862 )
5963
6064 assert extension ["type" ] == ThirdPartyAttributeExtension .THIRDPARTY_ATTRIBUTE
61- assert extension ["content" ]["expiry_date" ] == "2019-10-30T12:10:09.458000 "
65+ assert extension ["content" ]["expiry_date" ] == "2019-10-30T12:10:09.458Z "
6266
6367 assert extension ["content" ]["definitions" ][0 ]["name" ] == DEFINITION1
6468 assert extension ["content" ]["definitions" ][1 ]["name" ] == DEFINITION2
69+
70+
71+ @pytest .mark .parametrize (
72+ "expiry_date, expected_value" ,
73+ [
74+ (
75+ datetime (2051 , 1 , 13 , 19 , 50 , 53 , 1 , tzinfo = pytz .utc ),
76+ "2051-01-13T19:50:53.000Z" ,
77+ ),
78+ (
79+ datetime (2026 , 2 , 2 , 22 , 4 , 5 , 123 , tzinfo = pytz .utc ),
80+ "2026-02-02T22:04:05.000Z" ,
81+ ),
82+ (
83+ datetime (2051 , 4 , 13 , 19 , 50 , 53 , 999 , tzinfo = pytz .utc ),
84+ "2051-04-13T19:50:53.000Z" ,
85+ ),
86+ (
87+ datetime (2026 , 1 , 31 , 22 , 4 , 5 , 1232 , tzinfo = pytz .utc ),
88+ "2026-01-31T22:04:05.001Z" ,
89+ ),
90+ (
91+ datetime (2026 , 1 , 31 , 22 , 4 , 5 , 17777 , tzinfo = pytz .utc ),
92+ "2026-01-31T22:04:05.017Z" ,
93+ ),
94+ (
95+ datetime (2019 , 10 , 30 , 12 , 10 , 9 , int (458e3 ), tzinfo = pytz .utc ),
96+ "2019-10-30T12:10:09.458Z" ,
97+ ),
98+ (
99+ datetime (2026 , 1 , 2 , 22 , 4 , 5 , 123456 , tzinfo = pytz .utc ),
100+ "2026-01-02T22:04:05.123Z" ,
101+ ),
102+ ],
103+ )
104+ def test_should_format_utc_expiry_dates_correctly (expiry_date , expected_value ):
105+ DEFINITION = "some_value"
106+
107+ extension = (
108+ ThirdPartyAttributeExtension ()
109+ .with_expiry_date (expiry_date )
110+ .with_definitions (DEFINITION )
111+ .build ()
112+ )
113+
114+ assert extension ["content" ]["expiry_date" ] == expected_value
115+
116+
117+ @pytest .mark .parametrize (
118+ "expiry_date, tz_name" ,
119+ [
120+ (datetime (2030 , 6 , 6 , 8 , 0 , 0 , 0 ), "US/Eastern" ,),
121+ (datetime (2030 , 6 , 6 , 15 , 0 , 0 , 0 ), "Europe/Moscow" ,),
122+ (datetime (2030 , 6 , 6 , 7 , 0 , 0 , 0 ), "America/Jamaica" ,),
123+ (datetime (2030 , 6 , 6 , 23 , 0 , 0 , 0 ), "Etc/GMT-11" ),
124+ (datetime (2030 , 6 , 6 , 7 , 0 , 0 , 0 ), "Etc/GMT+5" ),
125+ # In order to conform with the POSIX style, those zones beginning
126+ # with "Etc/GMT" have their sign reversed from what most people expect. In this style, zones west of GMT have
127+ # a positive sign and those east have a negative sign.
128+ ],
129+ )
130+ def test_should_format_localized_expiry_dates (expiry_date , tz_name ):
131+ DEFINITION = "some_value"
132+
133+ tz = pytz .timezone (tz_name )
134+ localized_expiry_date = tz .localize (expiry_date )
135+
136+ extension = (
137+ ThirdPartyAttributeExtension ()
138+ .with_expiry_date (localized_expiry_date )
139+ .with_definitions (DEFINITION )
140+ .build ()
141+ )
142+
143+ assert extension ["content" ]["expiry_date" ] == "2030-06-06T12:00:00.000Z"
0 commit comments