Beispiel #1
0
    def test_basic_get_message_empty_queue(self):
        get_frame = specification.Basic.Get(queue='travis-ci', no_ack=False)

        def on_get_frame(*_):
            channel.rpc.on_frame(specification.Basic.GetEmpty())

        connection = FakeConnection(on_write=on_get_frame)
        channel = Channel(9, connection, 1)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        result = basic._get_message(get_frame, auto_decode=False)

        self.assertEqual(result, None)
Beispiel #2
0
    def test_basic_get_message_empty_queue(self):
        get_frame = specification.Basic.Get(queue='travis-ci',
                                            no_ack=False)

        def on_get_frame(*_):
            channel.rpc.on_frame(specification.Basic.GetEmpty())

        connection = FakeConnection(on_write=on_get_frame)
        channel = Channel(9, connection, 1)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        result = basic._get_message(get_frame, auto_decode=False)

        self.assertEqual(result, None)
Beispiel #3
0
    def test_basic_get_message_auto_decode(self):
        message = self.message.encode('utf-8')
        message_len = len(message)

        get_frame = specification.Basic.Get(queue='travis-ci', no_ack=False)

        def on_get_frame(*_):
            channel.rpc.on_frame(specification.Basic.GetOk())
            channel.rpc.on_frame(ContentHeader(body_size=message_len))
            channel.rpc.on_frame(ContentBody(value=message))

        connection = FakeConnection(on_write=on_get_frame)
        channel = Channel(9, connection, 1)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        result = basic._get_message(get_frame, auto_decode=True)

        self.assertEqual(result.body.encode('utf-8'), message)
Beispiel #4
0
    def test_basic_get_message_auto_decode(self):
        message = self.message.encode('utf-8')
        message_len = len(message)

        get_frame = specification.Basic.Get(queue='travis-ci',
                                            no_ack=False)

        def on_get_frame(*_):
            channel.rpc.on_frame(specification.Basic.GetOk())
            channel.rpc.on_frame(ContentHeader(body_size=message_len))
            channel.rpc.on_frame(ContentBody(value=message))

        connection = FakeConnection(on_write=on_get_frame)
        channel = Channel(9, connection, 1)
        channel.set_state(Channel.OPEN)
        basic = Basic(channel)

        result = basic._get_message(get_frame, auto_decode=True)

        self.assertEqual(result.body.encode('utf-8'), message)