Example #1
0
    def testProcessPacket(self):
        outter_msg = remoting.Message(target='null', response='/1')
        inner_msg = messaging.CommandMessage()
        inner_msg.destination = self.service_name
        inner_msg.operation = messaging.CommandMessage.CLIENT_PING_OPERATION
        inner_msg.headers = {'DSEndpoint': 'amf'}
        inner_msg.body = (None, )
        inner_msg.messageId = '123'
        outter_msg.body = (inner_msg, )

        packet = remoting.Packet(messages=[outter_msg])
        encoded_packet = self.channel.encode(packet)
        decoded_packet = self.channel.decode(encoded_packet)
        response = self.channel.invoke(decoded_packet)
        encoded_response = self.channel.encode(response)
        response = self.channel.endpoint.decodePacket(encoded_response)

        # Check outer msg
        self.assertEquals(1, len(response.messages))
        self.assertEquals(True,
                          response.messages[0].target.endswith('onResult'))
        self.assertEquals('', response.messages[0].response)

        # Check inner msg
        self.assertEquals(messaging.AcknowledgeMessage,
                          response.messages[0].body.__class__)
        self.assertEquals('123', response.messages[0].body.correlationId)
def packet_to_amfast(pyamf_packet):
    """Converts a PyAmf Envelope to an AmFast Packet.

    arguments:
    ===========
     * pyamf_packet - pyamf.remoting.Envelope.

    Returns amfast.remoting.Packet
    """
    if pyamf_packet.clientType == pyamf.ClientTypes.Flash6:
        client_type = amfast_remoting.Packet.FLASH_8
    elif pyamf_packet.clientType == pyamf.ClientTypes.FlashCom:
        client_type = amfast_remoting.Packet.FLASH_COM
    elif pyamf_packet.clientType == pyamf.ClientTypes.Flash9:
        client_type = amfast_remoting.Packet.FLASH_9
    else:
        clientType = amfast_remoting.Packet.FLASH_8 

    headers = [amfast_remoting.Header(name,
        required=pyamf_packet.headers.is_required(name), value=header) \
        for name, header in pyamf_packet.headers]

    messages = [message_to_amfast(name, body) for name, body in pyamf_packet.bodies]

    return amfast_remoting.Packet(client_type=client_type, headers=headers, messages=messages)
Example #3
0
    def testOldStyleTargetFault(self):
        message = remoting.Message(target='bad_target',
                                   response='/1',
                                   body=(self.arg, ))
        packet = remoting.Packet(messages=[message])
        packet.channel = self.channel
        response = packet.invoke()

        self.assertEquals(1, len(response.messages))
        self.assertEquals(True,
                          response.messages[0].target.endswith('onStatus'))
        self.assertEquals('', response.messages[0].response)
        self.assertEquals(remoting.AsError,
                          response.messages[0].body.__class__)
Example #4
0
    def testOldStyleTarget(self):
        qualified_name = self.service_name + '.' + self.target_name
        message = remoting.Message(target=qualified_name,
                                   response='/1',
                                   body=(self.arg, ))
        packet = remoting.Packet(messages=[message])
        packet.channel = self.channel
        response = packet.invoke()

        self.assertEquals(1, len(response.messages))
        self.assertEquals(True,
                          response.messages[0].target.endswith('onResult'))
        self.assertEquals('', response.messages[0].response)
        self.assertEquals(True, response.messages[0].body)
Example #5
0
    def testRoTarget(self):
        outter_msg = remoting.Message(target='null', response='/1')
        inner_msg = messaging.RemotingMessage()
        inner_msg.destination = self.service_name
        inner_msg.operation = self.target_name
        inner_msg.headers = {self.target_name: self.arg, 'DSEndpoint': 'amf'}
        inner_msg.body = (self.arg, )
        inner_msg.messageId = '123'
        outter_msg.body = (inner_msg, )

        packet = remoting.Packet(messages=[outter_msg])
        packet.channel = self.channel
        response = packet.invoke()

        # Check outer msg
        self.assertEquals(1, len(response.messages))
        self.assertEquals(True,
                          response.messages[0].target.endswith('onResult'))
        self.assertEquals('', response.messages[0].response)

        # Check inner msg
        self.assertEquals(True, response.messages[0].body.body)
        self.assertEquals('123', response.messages[0].body.correlationId)
Example #6
0
 def testHeaderTarget(self):
     header = remoting.Header(self.target_name, False, self.arg)
     packet = remoting.Packet(headers=[header])
     packet.channel = self.channel
     packet.invoke()