diff --git a/unittests/test_high_level_api.py b/unittests/test_high_level_api.py index 82c1a5caf0f0719b5946ecd6749b4079bb6794bc..e35dc678f7d0f44d1bb8fa763cf8dfc8225e3aee 100644 --- a/unittests/test_high_level_api.py +++ b/unittests/test_high_level_api.py @@ -322,6 +322,7 @@ def test_wrong_entity_for_file(): def test_serialization(): + # With ID r = db.Record(id=5, name="test", description="ok") r.add_property(name="v", value=15, datatype=db.INTEGER, unit="kpx", importance="RECOMMENDED") @@ -333,6 +334,22 @@ def test_serialization(): for teststr in teststrs: assert teststr in text + serialized = convert_to_python_object(r).serialize() + assert serialized == {'role': 'Record', + 'name': 'test', + 'id': 5, + 'description': 'ok', + 'properties': {'v': 15}, + 'parents': [], + 'metadata': {'v': {'unit': 'kpx', + 'datatype': 'INTEGER', + 'importance': 'RECOMMENDED'}}} + + serialized_plain = convert_to_python_object(r).serialize(plain_json=True) + assert serialized_plain == {'id': 5, 'name': 'test', 'v': 15} + + # Without ID + r = db.Record(description="ok") r.add_property(name="v", value=15, datatype=db.INTEGER, unit="kpx", importance="RECOMMENDED") @@ -341,6 +358,18 @@ def test_serialization(): assert "name" not in text assert "id" not in text + serialized = convert_to_python_object(r).serialize() + assert serialized == {'role': 'Record', + 'description': 'ok', + 'properties': {'v': 15}, + 'parents': [], + 'metadata': {'v': {'unit': 'kpx', + 'datatype': 'INTEGER', + 'importance': 'RECOMMENDED'}}} + + serialized_plain = convert_to_python_object(r).serialize(plain_json=True) + assert serialized_plain == {'id': None, 'name': None, 'v': 15} + def test_files(): # empty file: