22from uuid import UUID
33
44import pytest
5-
65import pendulum
76from kiota_serialization_json .json_serialization_writer import JsonSerializationWriter
87
@@ -72,20 +71,23 @@ def test_write_uuid_value():
7271 content = json_serialization_writer .get_serialized_content ()
7372 content_string = content .decode ('utf-8' )
7473 assert content_string == '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36"}'
75-
74+
75+
7676def test_write_uuid_value_with_valid_string ():
7777 json_serialization_writer = JsonSerializationWriter ()
7878 json_serialization_writer .write_uuid_value ("id" , "8f841f30-e6e3-439a-a812-ebd369559c36" )
7979 content = json_serialization_writer .get_serialized_content ()
8080 content_string = content .decode ('utf-8' )
8181 assert content_string == '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36"}'
82-
82+
83+
8384def test_write_uuid_value_with_invalid_string ():
8485 with pytest .raises (ValueError ) as excinfo :
8586 json_serialization_writer = JsonSerializationWriter ()
8687 json_serialization_writer .write_uuid_value ("id" , "invalid-uuid-string" )
8788 assert "Invalid UUID string value found for property id" in str (excinfo .value )
88-
89+
90+
8991def test_write_datetime_value ():
9092 json_serialization_writer = JsonSerializationWriter ()
9193 json_serialization_writer .write_datetime_value (
@@ -94,7 +96,8 @@ def test_write_datetime_value():
9496 content = json_serialization_writer .get_serialized_content ()
9597 content_string = content .decode ('utf-8' )
9698 assert content_string == '{"updatedAt": "2022-01-27T12:59:45.596117+00:00"}'
97-
99+
100+
98101def test_write_datetime_value_valid_string ():
99102 json_serialization_writer = JsonSerializationWriter ()
100103 json_serialization_writer .write_datetime_value (
@@ -103,25 +106,31 @@ def test_write_datetime_value_valid_string():
103106 content = json_serialization_writer .get_serialized_content ()
104107 content_string = content .decode ('utf-8' )
105108 assert content_string == '{"updatedAt": "2022-01-27T12:59:45.596117+00:00"}'
106-
107- def test_write_datetime_value_valid_string ():
109+
110+
111+ def test_write_datetime_value_invalid_string ():
108112 with pytest .raises (ValueError ) as excinfo :
109113 json_serialization_writer = JsonSerializationWriter ()
110114 json_serialization_writer .write_datetime_value (
111115 "updatedAt" , "invalid-datetime-string"
112116 )
113117 assert "Invalid datetime string value found for property updatedAt" in str (excinfo .value )
114118
119+
115120def test_write_timedelta_value ():
116121 json_serialization_writer = JsonSerializationWriter ()
117122 json_serialization_writer .write_timedelta_value (
118123 "diff" ,
119- (pendulum .parse ('2022-01-27T12:59:45.596117' ) - pendulum .parse ('2022-01-27T10:59:45.596117' )).as_timedelta ()
124+ (
125+ pendulum .parse ('2022-01-27T12:59:45.596117' ) -
126+ pendulum .parse ('2022-01-27T10:59:45.596117' )
127+ ).as_timedelta ()
120128 )
121129 content = json_serialization_writer .get_serialized_content ()
122130 content_string = content .decode ('utf-8' )
123131 assert content_string == '{"diff": "2:00:00"}'
124-
132+
133+
125134def test_write_timedelta_value_valid_string ():
126135 json_serialization_writer = JsonSerializationWriter ()
127136 json_serialization_writer .write_timedelta_value (
@@ -131,7 +140,8 @@ def test_write_timedelta_value_valid_string():
131140 content = json_serialization_writer .get_serialized_content ()
132141 content_string = content .decode ('utf-8' )
133142 assert content_string == '{"diff": "2:00:00"}'
134-
143+
144+
135145def test_write_timedelta_value_invalid_string ():
136146 with pytest .raises (ValueError ) as excinfo :
137147 json_serialization_writer = JsonSerializationWriter ()
@@ -140,7 +150,7 @@ def test_write_timedelta_value_invalid_string():
140150 "invalid-timedelta-string"
141151 )
142152 assert "Invalid timedelta string value found for property diff" in str (excinfo .value )
143-
153+
144154
145155def test_write_date_value ():
146156 json_serialization_writer = JsonSerializationWriter ()
@@ -149,19 +159,22 @@ def test_write_date_value():
149159 content_string = content .decode ('utf-8' )
150160 assert content_string == '{"birthday": "2000-09-04"}'
151161
162+
152163def test_write_date_value_valid_string ():
153164 json_serialization_writer = JsonSerializationWriter ()
154165 json_serialization_writer .write_date_value ("birthday" , "2000-09-04" )
155166 content = json_serialization_writer .get_serialized_content ()
156167 content_string = content .decode ('utf-8' )
157168 assert content_string == '{"birthday": "2000-09-04"}'
158-
169+
170+
159171def test_write_date_value_invalid_string ():
160172 with pytest .raises (ValueError ) as excinfo :
161173 json_serialization_writer = JsonSerializationWriter ()
162174 json_serialization_writer .write_date_value ("birthday" , "invalid-date-string" )
163175 assert "Invalid date string value found for property birthday" in str (excinfo .value )
164176
177+
165178def test_write_time_value ():
166179 json_serialization_writer = JsonSerializationWriter ()
167180 json_serialization_writer .write_time_value (
@@ -172,6 +185,7 @@ def test_write_time_value():
172185 content_string = content .decode ('utf-8' )
173186 assert content_string == '{"time": "12:59:45.596117"}'
174187
188+
175189def test_write_time_value_valid_string ():
176190 json_serialization_writer = JsonSerializationWriter ()
177191 json_serialization_writer .write_time_value (
@@ -181,7 +195,8 @@ def test_write_time_value_valid_string():
181195 content = json_serialization_writer .get_serialized_content ()
182196 content_string = content .decode ('utf-8' )
183197 assert content_string == '{"time": "12:59:45.596117"}'
184-
198+
199+
185200def test_write_time_value_invalid_string ():
186201 with pytest .raises (ValueError ) as excinfo :
187202 json_serialization_writer = JsonSerializationWriter ()
@@ -191,6 +206,7 @@ def test_write_time_value_invalid_string():
191206 )
192207 assert "Invalid time string value found for property time" in str (excinfo .value )
193208
209+
194210def test_write_collection_of_primitive_values ():
195211 json_serialization_writer = JsonSerializationWriter ()
196212 json_serialization_writer .write_collection_of_primitive_values (
@@ -206,9 +222,14 @@ def test_write_collection_of_object_values(user_1, user_2):
206222 json_serialization_writer .write_collection_of_object_values ("users" , [user_1 , user_2 ])
207223 content = json_serialization_writer .get_serialized_content ()
208224 content_string = content .decode ('utf-8' )
209- assert content_string == '{"users": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' \
210- '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' \
211- '{"display_name": "John Doe", "age": 32}]}'
225+ expected = (
226+ '{"users": ['
227+ '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '
228+ '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '
229+ '{"display_name": "John Doe", "age": 32}'
230+ ']}'
231+ )
232+ assert content_string == expected
212233
213234
214235def test_write_collection_of_enum_values ():
@@ -226,8 +247,13 @@ def test_write_object_value(user_1):
226247 json_serialization_writer .write_object_value ("user1" , user_1 )
227248 content = json_serialization_writer .get_serialized_content ()
228249 content_string = content .decode ('utf-8' )
229- assert content_string == '{"user1": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' \
230- '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}}'
250+ expected = (
251+ '{"user1": {'
252+ '"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '
253+ '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true'
254+ '}}'
255+ )
256+ assert content_string == expected
231257
232258
233259def test_write_enum_value ():
@@ -265,14 +291,18 @@ def test_write_additional_data_value(user_1, user_2):
265291 )
266292 content = json_serialization_writer .get_serialized_content ()
267293 content_string = content .decode ('utf-8' )
268- assert content_string == '{"@odata.context": ' \
269- '"https://graph.microsoft.com/v1.0/$metadata#users/$entity", ' \
270- '"businessPhones": ["+1 205 555 0108"], ' \
271- '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' \
272- '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' \
273- '"approvers": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' \
274- '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' \
275- '{"display_name": "John Doe", "age": 32}], ' \
276- '"created_at": "2022-01-27", ' \
277- '"updated_at": "2024-09-24T00:00:00", ' \
278- '"data": {"groups": [{"friends": [{"display_name": "John Doe", "age": 32}]}]}}'
294+ expected = (
295+ '{"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", '
296+ '"businessPhones": ["+1 205 555 0108"], '
297+ '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '
298+ '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '
299+ '"approvers": ['
300+ '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '
301+ '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '
302+ '{"display_name": "John Doe", "age": 32}'
303+ '], '
304+ '"created_at": "2022-01-27", '
305+ '"updated_at": "2024-09-24T00:00:00", '
306+ '"data": {"groups": [{"friends": [{"display_name": "John Doe", "age": 32}]}]}}'
307+ )
308+ assert content_string == expected
0 commit comments