From 44fa5b9a9d244923d5b3309fb374a29a60c81647 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 1 Sep 2025 10:19:48 +0200 Subject: [PATCH 1/3] Allow ints to be written as floats in json_serializer --- .../kiota_serialization_json/json_serialization_writer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/serialization/json/kiota_serialization_json/json_serialization_writer.py b/packages/serialization/json/kiota_serialization_json/json_serialization_writer.py index ecfdd793..912b64f3 100644 --- a/packages/serialization/json/kiota_serialization_json/json_serialization_writer.py +++ b/packages/serialization/json/kiota_serialization_json/json_serialization_writer.py @@ -73,11 +73,11 @@ def write_float_value(self, key: Optional[str], value: Optional[float]) -> None: key (Optional[str]): The key to be used for the written value. May be null. value (Optional[float]): The float value to be written. """ - if isinstance(value, float): + if isinstance(value, (float, int)): if key: - self.writer[key] = value + self.writer[key] = float(value) else: - self.value = value + self.value = float(value) def write_uuid_value(self, key: Optional[str], value: Optional[UUID]) -> None: """Writes the specified uuid value to the stream with an optional given key. From 45e6b7df7a25d489d10912abe425014e9397affb Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 9 Sep 2025 07:18:34 +0200 Subject: [PATCH 2/3] Added tests for json serialization writer --- .../unit/test_json_serialization_writer.py | 144 +++++++++++------- 1 file changed, 86 insertions(+), 58 deletions(-) diff --git a/packages/serialization/json/tests/unit/test_json_serialization_writer.py b/packages/serialization/json/tests/unit/test_json_serialization_writer.py index ad0bd2a8..b060260b 100644 --- a/packages/serialization/json/tests/unit/test_json_serialization_writer.py +++ b/packages/serialization/json/tests/unit/test_json_serialization_writer.py @@ -11,7 +11,9 @@ @pytest.fixture def user_1(): user = User() - user.updated_at = datetime(2022,1,27,12,59,45,596117).fromisoformat("2022-01-27T12:59:45.596117+00:00") + user.updated_at = datetime(2022, 1, 27, 12, 59, 45, 596117).fromisoformat( + "2022-01-27T12:59:45.596117+00:00" + ) user.is_active = True user.id = UUID("8f841f30-e6e3-439a-a812-ebd369559c36") return user @@ -29,7 +31,7 @@ def test_write_str_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_str_value("displayName", "Adele Vance") content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"displayName": "Adele Vance"}' @@ -37,7 +39,7 @@ def test_write_string_value_no_key(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_str_value(None, "Adele Vance") content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '"Adele Vance"' @@ -45,7 +47,7 @@ def test_write_bool_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_bool_value("isActive", True) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"isActive": true}' @@ -53,7 +55,7 @@ def test_write_int_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_int_value("timestamp", 28192199291929192) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"timestamp": 28192199291929192}' @@ -61,23 +63,35 @@ def test_write_float_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_float_value("gpa", 3.2) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"gpa": 3.2}' +def test_write_float_value_with_int(): + json_serialization_writer = JsonSerializationWriter() + json_serialization_writer.write_float_value("float", 3) + content = json_serialization_writer.get_serialized_content() + content_string = content.decode("utf-8") + assert content_string == '{"float": 3.0}' + + def test_write_uuid_value(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_uuid_value("id", UUID("8f841f30-e6e3-439a-a812-ebd369559c36")) + json_serialization_writer.write_uuid_value( + "id", UUID("8f841f30-e6e3-439a-a812-ebd369559c36") + ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36"}' def test_write_uuid_value_with_valid_string(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_uuid_value("id", "8f841f30-e6e3-439a-a812-ebd369559c36") + json_serialization_writer.write_uuid_value( + "id", "8f841f30-e6e3-439a-a812-ebd369559c36" + ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36"}' @@ -91,38 +105,45 @@ def test_write_uuid_value_with_invalid_string(): def test_write_datetime_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_datetime_value( - "updatedAt", datetime.fromisoformat('2022-01-27T12:59:45.596117+00:00') + "updatedAt", datetime.fromisoformat("2022-01-27T12:59:45.596117+00:00") ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"updatedAt": "2022-01-27T12:59:45.596117+00:00"}' def test_write_datetime_value_valid_string(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_datetime_value("updatedAt", "2022-01-27T12:59:45.596117") + json_serialization_writer.write_datetime_value( + "updatedAt", "2022-01-27T12:59:45.596117" + ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"updatedAt": "2022-01-27T12:59:45.596117+00:00"}' def test_write_datetime_value_valid_string(): with pytest.raises(ValueError) as excinfo: json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_datetime_value("updatedAt", "invalid-datetime-string") - assert "Invalid datetime string value found for property updatedAt" in str(excinfo.value) + json_serialization_writer.write_datetime_value( + "updatedAt", "invalid-datetime-string" + ) + assert "Invalid datetime string value found for property updatedAt" in str( + excinfo.value + ) def test_write_timedelta_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_timedelta_value( - "diff", ( - datetime.fromisoformat('2022-01-27T12:59:45.596117') - - datetime.fromisoformat('2022-01-27T10:59:45.596117') - ) + "diff", + ( + datetime.fromisoformat("2022-01-27T12:59:45.596117") + - datetime.fromisoformat("2022-01-27T10:59:45.596117") + ), ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"diff": "2:00:00"}' @@ -130,22 +151,26 @@ def test_write_timedelta_value_valid_string(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_timedelta_value("diff", "2:00:00") content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"diff": "2:00:00"}' def test_write_timedelta_value_invalid_string(): with pytest.raises(ValueError) as excinfo: json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_timedelta_value("diff", "invalid-timedelta-string") - assert "Invalid timedelta string value found for property diff" in str(excinfo.value) + json_serialization_writer.write_timedelta_value( + "diff", "invalid-timedelta-string" + ) + assert "Invalid timedelta string value found for property diff" in str( + excinfo.value + ) def test_write_date_value(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_date_value("birthday", date(2000,9,4)) + json_serialization_writer.write_date_value("birthday", date(2000, 9, 4)) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"birthday": "2000-09-04"}' @@ -153,7 +178,7 @@ def test_write_date_value_valid_string(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_date_value("birthday", "2000-09-04") content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"birthday": "2000-09-04"}' @@ -167,11 +192,10 @@ def test_write_date_value_invalid_string(): def test_write_time_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_time_value( - "time", - datetime.fromisoformat('2022-01-27T12:59:45.596117').time() + "time", datetime.fromisoformat("2022-01-27T12:59:45.596117").time() ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"time": "12:59:45.596117"}' @@ -179,7 +203,7 @@ def test_write_time_value_valid_string(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_time_value("time", "12:59:45.596117") content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"time": "12:59:45.596117"}' @@ -196,18 +220,22 @@ def test_write_collection_of_primitive_values(): "businessPhones", ["+1 412 555 0109", 1] ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"businessPhones": ["+1 412 555 0109", 1]}' def test_write_collection_of_object_values(user_1, user_2): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_collection_of_object_values("users", [user_1, user_2]) + json_serialization_writer.write_collection_of_object_values( + "users", [user_1, user_2] + ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') - assert content_string == '{"users": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ + content_string = content.decode("utf-8") + assert ( + content_string == '{"users": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' '{"display_name": "John Doe", "age": 32}]}' + ) def test_write_collection_of_enum_values(): @@ -216,7 +244,7 @@ def test_write_collection_of_enum_values(): "officeLocation", [OfficeLocation.Dunhill, OfficeLocation.Oval] ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"officeLocation": ["dunhill", "oval"]}' @@ -224,16 +252,18 @@ def test_write_object_value(user_1): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_object_value("user1", user_1) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') - assert content_string == '{"user1": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ + content_string = content.decode("utf-8") + assert ( + content_string == '{"user1": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}}' + ) def test_write_enum_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_enum_value("officeLocation", OfficeLocation.Dunhill) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"officeLocation": "dunhill"}' @@ -241,7 +271,7 @@ def test_write_null_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_null_value("mobilePhone") content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') + content_string = content.decode("utf-8") assert content_string == '{"mobilePhone": null}' @@ -254,23 +284,21 @@ def test_write_additional_data_value(user_1, user_2): "manager": user_1, "approvers": [user_1, user_2], "created_at": date(2022, 1, 27), - "data": { - "groups": [{ - "friends": [user_2] - }] - }, - "pinnedItems": [None, None] + "data": {"groups": [{"friends": [user_2]}]}, + "pinnedItems": [None, None], } ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode('utf-8') - assert content_string == '{"@odata.context": '\ - '"https://graph.microsoft.com/v1.0/$metadata#users/$entity", '\ - '"businessPhones": ["+1 205 555 0108"], '\ - '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ - '"approvers": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ - '{"display_name": "John Doe", "age": 32}], "created_at": "2022-01-27", '\ - '"data": {"groups": [{"friends": [{"display_name": "John Doe", "age": 32}]}]}, '\ - '"pinnedItems": [null, null]}' + content_string = content.decode("utf-8") + assert ( + content_string == '{"@odata.context": ' + '"https://graph.microsoft.com/v1.0/$metadata#users/$entity", ' + '"businessPhones": ["+1 205 555 0108"], ' + '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' + '"approvers": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' + '{"display_name": "John Doe", "age": 32}], "created_at": "2022-01-27", ' + '"data": {"groups": [{"friends": [{"display_name": "John Doe", "age": 32}]}]}, ' + '"pinnedItems": [null, null]}' + ) From 880bf0818d692a2c0850f8b49c6d050cb3c78d4d Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 9 Sep 2025 09:20:07 +0200 Subject: [PATCH 3/3] Remove added formatting --- .../unit/test_json_serialization_writer.py | 136 ++++++++---------- 1 file changed, 58 insertions(+), 78 deletions(-) diff --git a/packages/serialization/json/tests/unit/test_json_serialization_writer.py b/packages/serialization/json/tests/unit/test_json_serialization_writer.py index b060260b..8168318e 100644 --- a/packages/serialization/json/tests/unit/test_json_serialization_writer.py +++ b/packages/serialization/json/tests/unit/test_json_serialization_writer.py @@ -11,9 +11,7 @@ @pytest.fixture def user_1(): user = User() - user.updated_at = datetime(2022, 1, 27, 12, 59, 45, 596117).fromisoformat( - "2022-01-27T12:59:45.596117+00:00" - ) + user.updated_at = datetime(2022,1,27,12,59,45,596117).fromisoformat("2022-01-27T12:59:45.596117+00:00") user.is_active = True user.id = UUID("8f841f30-e6e3-439a-a812-ebd369559c36") return user @@ -31,7 +29,7 @@ def test_write_str_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_str_value("displayName", "Adele Vance") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"displayName": "Adele Vance"}' @@ -39,7 +37,7 @@ def test_write_string_value_no_key(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_str_value(None, "Adele Vance") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '"Adele Vance"' @@ -47,7 +45,7 @@ def test_write_bool_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_bool_value("isActive", True) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"isActive": true}' @@ -55,7 +53,7 @@ def test_write_int_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_int_value("timestamp", 28192199291929192) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"timestamp": 28192199291929192}' @@ -63,7 +61,7 @@ def test_write_float_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_float_value("gpa", 3.2) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"gpa": 3.2}' @@ -77,21 +75,17 @@ def test_write_float_value_with_int(): def test_write_uuid_value(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_uuid_value( - "id", UUID("8f841f30-e6e3-439a-a812-ebd369559c36") - ) + json_serialization_writer.write_uuid_value("id", UUID("8f841f30-e6e3-439a-a812-ebd369559c36")) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36"}' def test_write_uuid_value_with_valid_string(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_uuid_value( - "id", "8f841f30-e6e3-439a-a812-ebd369559c36" - ) + json_serialization_writer.write_uuid_value("id", "8f841f30-e6e3-439a-a812-ebd369559c36") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"id": "8f841f30-e6e3-439a-a812-ebd369559c36"}' @@ -105,45 +99,38 @@ def test_write_uuid_value_with_invalid_string(): def test_write_datetime_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_datetime_value( - "updatedAt", datetime.fromisoformat("2022-01-27T12:59:45.596117+00:00") + "updatedAt", datetime.fromisoformat('2022-01-27T12:59:45.596117+00:00') ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"updatedAt": "2022-01-27T12:59:45.596117+00:00"}' def test_write_datetime_value_valid_string(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_datetime_value( - "updatedAt", "2022-01-27T12:59:45.596117" - ) + json_serialization_writer.write_datetime_value("updatedAt", "2022-01-27T12:59:45.596117") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"updatedAt": "2022-01-27T12:59:45.596117+00:00"}' def test_write_datetime_value_valid_string(): with pytest.raises(ValueError) as excinfo: json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_datetime_value( - "updatedAt", "invalid-datetime-string" - ) - assert "Invalid datetime string value found for property updatedAt" in str( - excinfo.value - ) + json_serialization_writer.write_datetime_value("updatedAt", "invalid-datetime-string") + assert "Invalid datetime string value found for property updatedAt" in str(excinfo.value) def test_write_timedelta_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_timedelta_value( - "diff", - ( - datetime.fromisoformat("2022-01-27T12:59:45.596117") - - datetime.fromisoformat("2022-01-27T10:59:45.596117") - ), + "diff", ( + datetime.fromisoformat('2022-01-27T12:59:45.596117') - + datetime.fromisoformat('2022-01-27T10:59:45.596117') + ) ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"diff": "2:00:00"}' @@ -151,26 +138,22 @@ def test_write_timedelta_value_valid_string(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_timedelta_value("diff", "2:00:00") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"diff": "2:00:00"}' def test_write_timedelta_value_invalid_string(): with pytest.raises(ValueError) as excinfo: json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_timedelta_value( - "diff", "invalid-timedelta-string" - ) - assert "Invalid timedelta string value found for property diff" in str( - excinfo.value - ) + json_serialization_writer.write_timedelta_value("diff", "invalid-timedelta-string") + assert "Invalid timedelta string value found for property diff" in str(excinfo.value) def test_write_date_value(): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_date_value("birthday", date(2000, 9, 4)) + json_serialization_writer.write_date_value("birthday", date(2000,9,4)) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"birthday": "2000-09-04"}' @@ -178,7 +161,7 @@ def test_write_date_value_valid_string(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_date_value("birthday", "2000-09-04") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"birthday": "2000-09-04"}' @@ -192,10 +175,11 @@ def test_write_date_value_invalid_string(): def test_write_time_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_time_value( - "time", datetime.fromisoformat("2022-01-27T12:59:45.596117").time() + "time", + datetime.fromisoformat('2022-01-27T12:59:45.596117').time() ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"time": "12:59:45.596117"}' @@ -203,7 +187,7 @@ def test_write_time_value_valid_string(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_time_value("time", "12:59:45.596117") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"time": "12:59:45.596117"}' @@ -220,22 +204,18 @@ def test_write_collection_of_primitive_values(): "businessPhones", ["+1 412 555 0109", 1] ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"businessPhones": ["+1 412 555 0109", 1]}' def test_write_collection_of_object_values(user_1, user_2): json_serialization_writer = JsonSerializationWriter() - json_serialization_writer.write_collection_of_object_values( - "users", [user_1, user_2] - ) + json_serialization_writer.write_collection_of_object_values("users", [user_1, user_2]) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") - assert ( - content_string == '{"users": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' + content_string = content.decode('utf-8') + assert content_string == '{"users": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ '{"display_name": "John Doe", "age": 32}]}' - ) def test_write_collection_of_enum_values(): @@ -244,7 +224,7 @@ def test_write_collection_of_enum_values(): "officeLocation", [OfficeLocation.Dunhill, OfficeLocation.Oval] ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"officeLocation": ["dunhill", "oval"]}' @@ -252,18 +232,16 @@ def test_write_object_value(user_1): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_object_value("user1", user_1) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") - assert ( - content_string == '{"user1": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' + content_string = content.decode('utf-8') + assert content_string == '{"user1": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}}' - ) def test_write_enum_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_enum_value("officeLocation", OfficeLocation.Dunhill) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"officeLocation": "dunhill"}' @@ -271,7 +249,7 @@ def test_write_null_value(): json_serialization_writer = JsonSerializationWriter() json_serialization_writer.write_null_value("mobilePhone") content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") + content_string = content.decode('utf-8') assert content_string == '{"mobilePhone": null}' @@ -284,21 +262,23 @@ def test_write_additional_data_value(user_1, user_2): "manager": user_1, "approvers": [user_1, user_2], "created_at": date(2022, 1, 27), - "data": {"groups": [{"friends": [user_2]}]}, - "pinnedItems": [None, None], + "data": { + "groups": [{ + "friends": [user_2] + }] + }, + "pinnedItems": [None, None] } ) content = json_serialization_writer.get_serialized_content() - content_string = content.decode("utf-8") - assert ( - content_string == '{"@odata.context": ' - '"https://graph.microsoft.com/v1.0/$metadata#users/$entity", ' - '"businessPhones": ["+1 205 555 0108"], ' - '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' - '"approvers": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", ' - '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, ' - '{"display_name": "John Doe", "age": 32}], "created_at": "2022-01-27", ' - '"data": {"groups": [{"friends": [{"display_name": "John Doe", "age": 32}]}]}, ' - '"pinnedItems": [null, null]}' - ) + content_string = content.decode('utf-8') + assert content_string == '{"@odata.context": '\ + '"https://graph.microsoft.com/v1.0/$metadata#users/$entity", '\ + '"businessPhones": ["+1 205 555 0108"], '\ + '"manager": {"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ + '"approvers": [{"id": "8f841f30-e6e3-439a-a812-ebd369559c36", '\ + '"updated_at": "2022-01-27T12:59:45.596117+00:00", "is_active": true}, '\ + '{"display_name": "John Doe", "age": 32}], "created_at": "2022-01-27", '\ + '"data": {"groups": [{"friends": [{"display_name": "John Doe", "age": 32}]}]}, '\ + '"pinnedItems": [null, null]}'