def test_parse_get_leader(self):
        d0 = ncore.NodeDescriptor(host_port="localhost:8000")
        msg = ncore.GetLeader(destination=d0)

        req = nhttp.build_request(msg)
        parsed = nhttp.parse_request(req)
        self.assertEqual(parsed, msg)
    def test_parse_new_predecessor(self):
        d0 = ncore.NodeDescriptor(host_port="localhost:8000")
        d1 = ncore.NodeDescriptor(host_port="localhost:8001")
        msg = ncore.NewPredecessor(destination=d1, predecessor=d0)

        req = nhttp.build_request(msg)
        parsed = nhttp.parse_request(req)
        self.assertEqual(parsed, msg)
    def test_parse_join(self):
        d0 = ncore.NodeDescriptor(host_port="localhost:8000")
        d1 = ncore.NodeDescriptor(host_port="localhost:8001")
        msg = ncore.Join(destination=d0, new_node=d1)

        req = nhttp.build_request(msg)
        parsed = nhttp.parse_request(req)
        self.assertEqual(parsed, msg)
    def test_parse_election_result(self):
        d0 = ncore.NodeDescriptor(host_port="localhost:8000")
        d1 = ncore.NodeDescriptor(host_port="localhost:8001")
        msg = ncore.ElectionResult(destination=d0, new_leader=d1)

        req = nhttp.build_request(msg)
        parsed = nhttp.parse_request(req)
        self.assertEqual(parsed, msg)
    def test_parse_election(self):
        d0 = ncore.NodeDescriptor(host_port="localhost:8000")
        d1 = ncore.NodeDescriptor(host_port="localhost:8001")
        msg = ncore.Election(destination=d0, participants=[d0,d1])

        req = nhttp.build_request(msg)
        parsed = nhttp.parse_request(req)
        self.assertEqual(parsed, msg)
    def test_parse_join_accept(self):
        d0 = ncore.NodeDescriptor(host_port="localhost:8000")
        d1 = ncore.NodeDescriptor(host_port="localhost:8001")
        d2 = ncore.NodeDescriptor(host_port="localhost:8002")
        d3 = ncore.NodeDescriptor(host_port="localhost:8003")
        msg = ncore.JoinAccepted(destination=d1, successor=d2, predecessor=d0, leader=d3)

        req = nhttp.build_request(msg)
        parsed = nhttp.parse_request(req)
        self.assertEqual(parsed, msg)