Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_serializers.py
- This file was added.
# Copyright (C) 2020 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from swh.storage.api.serializers import ( | |||||
_encode_model_object, | |||||
_decode_model_object, | |||||
) | |||||
def test_model_object_serialization(sample_data): | |||||
content = sample_data.content | |||||
actual_content_dict = _encode_model_object(content) | |||||
expected_content_dict = content.to_dict() | |||||
expected_content_dict["__type__"] = type(content).__name__ | |||||
assert actual_content_dict == expected_content_dict | |||||
decoded_content = _decode_model_object(actual_content_dict) | |||||
assert decoded_content == content |