def test_json_proto_api_read(): obj = TItem(id=13, phones=["5234", "12346456"]) trans = TMemoryBuffer() p = TJSONProtocol(trans) p.write_struct(obj) obj2 = TItem() obj2 = p.read_struct(obj2) assert obj.id == 13 and obj.phones == ["5234", "12346456"]
def test_json_proto_api_read(): obj = TItem(id=13, phones=["5234", "12346456"]) trans = TMemoryBuffer() p = TJSONProtocol(trans) p.write_struct(obj) obj2 = TItem() obj2 = p.read_struct(obj2) assert obj.id == 13 and obj.phones == ["5234", "12346456"]
def test_json_proto_api_write(): obj = TItem(id=13, phones=["5234", "12346456"]) trans = TMemoryBuffer() p = TJSONProtocol(trans) p.write_struct(obj) data = trans.getvalue().decode("utf-8") length = data[0:4] import json data = json.loads(data[4:]) assert length == "\x00\x00\x00S" and data == { "metadata": {"version": 1}, "payload": {"phones": ["5234", "12346456"], "id": 13}}
def test_json_proto_api_write(): obj = TItem(id=13, phones=["5234", "12346456"]) trans = TMemoryBuffer() p = TJSONProtocol(trans) p.write_struct(obj) data = trans.getvalue().decode("utf-8") length = data[0:4] import json data = json.loads(data[4:]) assert length == "\x00\x00\x00S" and data == { "metadata": {"version": 1}, "payload": {"phones": ["5234", "12346456"], "id": 13}}