Exemplo n.º 1
0
    def testCreateResponse(self):
        ep = Endpoint(host='localhost')
        reqm = ep.create_request('/path', messageID=1, token=b'1', confirmable=True)
        self.assertTrue(reqm.destination_endpoint is ep)

        rspm = reqm.create_response(SuccessResponse, code=SuccessResponse.Content)
        self.assertTrue(rspm.is_acknowledgement())
        self.assertEqual(rspm.messageID, reqm.messageID)
        self.assertEqual(rspm.token, reqm.token)
        self.assertEqual(rspm.code, SuccessResponse.Content)
        self.assertTrue(rspm.source_endpoint is ep)

        rspm = reqm.create_response(SuccessResponse,
                                    piggy_backed=False,
                                    code=SuccessResponse.Content)
        self.assertTrue(rspm.is_non_confirmable())
        self.assertTrue(rspm.messageID is None)
        self.assertEqual(rspm.token, reqm.token)
        self.assertEqual(rspm.code, SuccessResponse.Content)
        self.assertTrue(rspm.source_endpoint is ep)

        rspm = reqm.create_response(SuccessResponse,
                                    piggy_backed=False,
                                    confirmable=True,
                                    code=SuccessResponse.Content)
        self.assertTrue(rspm.is_confirmable())
        self.assertTrue(rspm.messageID is None)
        self.assertEqual(rspm.token, reqm.token)
        self.assertEqual(rspm.code, SuccessResponse.Content)
        self.assertTrue(rspm.source_endpoint is ep)
Exemplo n.º 2
0
    def testNON(self):
        ep = Endpoint(host='localhost')
        non = ep.create_request('/path', messageID=2, token=b'2', confirmable=False)
        with self.assertRaises(MessageReplyError) as cm:
            non.create_reply()
        exc = cm.exception
        self.assertEqual(exc.args[0], MessageReplyError.ACK_FOR_NON)
        self.assertEqual(exc.args[1], non)

        rep = non.create_reply(reset=True)
        self.assertEqual(rep.messageID, non.messageID)
        self.assertEqual(rep.token, b'')
        self.assertTrue(rep.is_reset())
        self.assertTrue(rep.source_endpoint is non.destination_endpoint)
        self.assertTrue(rep.destination_endpoint is non.source_endpoint)
        data = rep.to_packed()
        self.assertEqual(4, len(data))
Exemplo n.º 3
0
    def testCON(self):
        ep = Endpoint(host='localhost')
        con = ep.create_request('/path', messageID=1, token=b'1', confirmable=True)
        rep = con.create_reply()
        self.assertEqual(rep.messageID, con.messageID)
        self.assertEqual(rep.token, b'')
        self.assertTrue(rep.is_acknowledgement())
        self.assertTrue(rep.source_endpoint is con.destination_endpoint)
        self.assertTrue(rep.destination_endpoint is con.source_endpoint)
        data = rep.to_packed()
        self.assertEqual(4, len(data))

        rep = con.create_reply(reset=True)
        self.assertEqual(rep.messageID, con.messageID)
        self.assertEqual(rep.token, b'')
        self.assertTrue(rep.is_reset())
        self.assertTrue(rep.source_endpoint is con.destination_endpoint)
        self.assertTrue(rep.destination_endpoint is con.source_endpoint)
        data = rep.to_packed()
        self.assertEqual(4, len(data))