def test_basic_publish(self): message = str(uuid.uuid4()) exchange = 'test' routing_key = 'hello' properties = {'headers': {'key': 'value'}} connection = FakeConnection() channel = Channel(9, connection, 0.0001) channel.set_state(Channel.OPEN) basic = Basic(channel) basic.publish(body=message, routing_key=routing_key, exchange=exchange, properties=properties, mandatory=True, immediate=True) channel_id, payload = connection.frames_out.pop() basic_publish, content_header, content_body = payload # Verify Channel ID self.assertEqual(channel_id, 9) # Verify Classes self.assertIsInstance(basic_publish, spec_basic.Publish) self.assertIsInstance(content_header, ContentHeader) self.assertIsInstance(content_body, ContentBody) # Verify Content self.assertEqual(message, content_body.value.decode('utf-8')) self.assertEqual(exchange, basic_publish.exchange) self.assertEqual(routing_key, basic_publish.routing_key) self.assertTrue(basic_publish.immediate) self.assertTrue(basic_publish.mandatory) self.assertIn('key', dict(content_header.properties)['headers'])
def test_basic_publish_confirms_nack(self): def on_publish_return_nack(*_): channel.rpc.on_frame(specification.Basic.Nack()) connection = FakeConnection(on_write=on_publish_return_nack) channel = Channel(9, connection, 1) channel._confirming_deliveries = True channel.set_state(Channel.OPEN) basic = Basic(channel) self.assertFalse( basic.publish(body=self.message, routing_key='travis-ci'))
def test_basic_publish_confirms_nack(self): def on_publish_return_nack(*_): channel.rpc.on_frame(specification.Basic.Nack()) connection = FakeConnection(on_write=on_publish_return_nack) channel = Channel(9, connection, 1) channel._confirming_deliveries = True channel.set_state(Channel.OPEN) basic = Basic(channel) self.assertFalse(basic.publish(body=self.message, routing_key='travis-ci'))
def test_basic_publish_confirms_nack(self): message = str(uuid.uuid4()) def on_publish_return_nack(*_): channel.rpc.on_frame(spec_basic.Nack()) connection = FakeConnection(on_write=on_publish_return_nack) channel = Channel(9, connection, 1) channel.confirming_deliveries = True channel.set_state(Channel.OPEN) basic = Basic(channel) self.assertFalse(basic.publish(body=message, routing_key='unittest'))
def test_basic_publish(self): message = str(uuid.uuid4()) exchange = 'test' routing_key = 'hello' properties = {'headers': { 'key': 'value' }} connection = FakeConnection() channel = Channel(9, connection, 0.0001) channel.set_state(Channel.OPEN) basic = Basic(channel) basic.publish(body=message, routing_key=routing_key, exchange=exchange, properties=properties, mandatory=True, immediate=True) channel_id, payload = connection.frames_out.pop() basic_publish, content_header, content_body = payload # Verify Channel ID self.assertEqual(channel_id, 9) # Verify Classes self.assertIsInstance(basic_publish, spec_basic.Publish) self.assertIsInstance(content_header, ContentHeader) self.assertIsInstance(content_body, ContentBody) # Verify Content self.assertEqual(message, content_body.value.decode('utf-8')) self.assertEqual(exchange, basic_publish.exchange) self.assertEqual(routing_key, basic_publish.routing_key) self.assertTrue(basic_publish.immediate) self.assertTrue(basic_publish.mandatory) self.assertIn('key', dict(content_header.properties)['headers'])