From be2c8f078cb06de7c3806e08929afbf6927652d2 Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Sat, 12 Feb 2022 15:27:30 +0200 Subject: [PATCH] Metadata test full serialization cycle Replace the usage of Metadata.to_dict inside test_valid_metadata_serialization and instead use Metadata.to_bytes() in order to test that the full serialization cycle is working as expected: Metadata.from_bytes -> Metadata.to_bytes Signed-off-by: Martin Vrachev --- tests/test_metadata_serialization.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_metadata_serialization.py b/tests/test_metadata_serialization.py index 082d1745b4..a27e7bd6e6 100644 --- a/tests/test_metadata_serialization.py +++ b/tests/test_metadata_serialization.py @@ -73,8 +73,15 @@ def test_invalid_metadata_serialization(self, test_data: bytes) -> None: @utils.run_sub_tests_with_dataset(valid_metadata) def test_valid_metadata_serialization(self, test_case_data: bytes) -> None: md = Metadata.from_bytes(test_case_data) - input_dict = json.loads(test_case_data) - self.assertDictEqual(input_dict, md.to_dict()) + + # Convert to a JSON and sort the keys the way we do in JSONSerializer. + separators = (",", ":") + test_json = json.loads(test_case_data) + test_bytes = json.dumps( + test_json, separators=separators, sort_keys=True + ).encode("utf-8") + + self.assertEqual(test_bytes, md.to_bytes()) invalid_signatures: utils.DataSet = { "missing keyid attribute in a signature": '{ "sig": "abc" }',