Esempio n. 1
0
    def test_call_1(self):
        """ Test if the sessions call handler is called when an unidirectional call packet is
        received.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(True)

        session = chan.session('name')
        handler = Mock()
        session.add_call_handler(handler)

        conn.mock_downstream_verb(verbs.CallVerb(
            unidirectional=False,
            postref=1,
            name=b'name',
            payload=b'payload',
        ))

        self.__verify_handler_call(
            handler,
            Call,
            unidirectional=False,
            name='name',
            postref=1,
            payload='payload',
        )
Esempio n. 2
0
    def __on_call_packet(self, packet):
        """ Called when a call packet has been received.
        """

        # create verb from packet and send it downstream
        verb = verbs.CallVerb(
            unidirectional=packet.unidirectional,
            postref=packet.postref if not packet.unidirectional else None,
            name=packet.name,
            payload=packet.payload,
        )

        if self.downstream_handler:
            self.downstream_handler(verb)
Esempio n. 3
0
    def test_call_post_warning(self):
        """ Test if a warning is logged when a post is attempted on an unidirectional call.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        verb = verbs.CallVerb(
            unidirectional=True,
            postref=None,
            name=b'name',
            payload=b'payload'
        )

        call = Call(chan.core, verb, None)

        with self.assertLogs(channel.logger, level='WARNING'):
            call.post('payload')
Esempio n. 4
0
def test_call_2(self):
    """ Test that a Call verb is produced.
    """

    mock = Sysmock()
    mock.system.add_unused_local_address(CLIENT)

    downstream_handler = unittest.mock.Mock()

    with patch(mock):
        loop = Mainloop()

        mock.expect_tcp_syn(CLIENT, SERVER)
        mock.do_tcp_syn_ack(SERVER, CLIENT)
        mock.do_tcp_input(SERVER, CLIENT, packets.welcome())

        # send the packet
        mock.do_tcp_input(
            SERVER, CLIENT,
            packets.call(
                unidirectional=True,
                postref=1234,
                name=b'name',
                payload=b'payload',
            ))

        conn = NxtcpConnection(loop, SERVER.address)
        conn.set_downstream_handler(downstream_handler)

        mock.run_events(loop.run_once)

        # verify the verb
        downstream_handler.assert_called_once_with(
            verbs.CallVerb(
                unidirectional=True,
                postref=None,
                name=b'name',
                payload=b'payload',
            ))