def test_header_serialization(self): node = Node(node_name="test node", pub_addr="10.10.10.10", pub_port=1023) task_header = TaskHeader( task_id="xyz", environment="DEFAULT", task_owner=node) # ignore dynamic properties task_header.fixed_header.last_checking = 0 task_header_dict = task_header.to_dict() serialized = CBORSerializer.dumps(task_header_dict) deserialized = CBORSerializer.loads(serialized) task_header_from_dict = TaskHeader.from_dict(deserialized) # ignore dynamic properties task_header_from_dict.fixed_header.last_checking = 0 assert task_header_from_dict.to_dict() == task_header_dict assert isinstance(task_header_from_dict.task_owner, Node) task_header_bin = task_header.to_binary() bin_serialized = CBORSerializer.dumps(task_header_bin) bin_deserialized = CBORSerializer.loads(bin_serialized) assert bin_deserialized == task_header_bin
def test_header_serialization(self): node = dict(node_name="test node") docker_images = [ dict(repository="repo_{}".format(i), id="id_{}".format(i), tag="tag_{}".format(i)) for i in xrange(4) ] task_header = TaskHeader("ABC", "xyz", "10.10.10.10", 1023, "key", "DEFAULT", task_owner=node, docker_images=docker_images) # ignore dynamic properties task_header.last_checking = 0 task_header_dict = task_header.to_dict() serialized = CBORSerializer.dumps(task_header_dict) deserialized = CBORSerializer.loads(serialized) task_header_from_dict = TaskHeader.from_dict(deserialized) # ignore dynamic properties task_header_from_dict.last_checking = 0 assert task_header_from_dict.to_dict() == task_header_dict assert isinstance(task_header_from_dict.task_owner, Node) assert all([ isinstance(di, DockerImage) for di in task_header_from_dict.docker_images ]) task_header_bin = task_header.to_binary() bin_serialized = CBORSerializer.dumps(task_header_bin) bin_deserialized = CBORSerializer.loads(bin_serialized) assert bin_deserialized == task_header_bin