Esempio n. 1
0
    def test_channel_start_consuming_no_consumer_tag(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(channel.OPEN)

        message = self.message.encode('utf-8')
        message_len = len(message)

        deliver = specification.Basic.Deliver()
        header = ContentHeader(body_size=message_len)
        body = ContentBody(value=message)

        channel._inbound = [deliver, header, body]

        def callback(msg):
            self.assertIsInstance(msg.body, str)
            self.assertEqual(msg.body.encode('utf-8'), message)

        channel.consumer_callback = callback
        channel.start_consuming()
Esempio n. 2
0
    def test_channel_process_data_events_as_tuple(self):
        channel = Channel(0, FakeConnection(), 360)
        channel.set_state(channel.OPEN)

        message = self.message.encode('utf-8')
        message_len = len(message)

        deliver = specification.Basic.Deliver()
        header = ContentHeader(body_size=message_len)
        body = ContentBody(value=message)

        channel._inbound = [deliver, header, body]

        def callback(body, channel, method, properties):
            self.assertIsInstance(body, bytes)
            self.assertIsInstance(channel, Channel)
            self.assertIsInstance(method, dict)
            self.assertIsInstance(properties, dict)
            self.assertEqual(body, message)

        channel.consumer_callback = callback
        channel.process_data_events(to_tuple=True)