Esempio n. 1
0
 def test_write(self):
     captive_queue = self.captive_rabbit.make_queue()
     queue = self.rabbit.queue(captive_queue.name)
     queue.publish(rabbit_droppings.Message("foo"))
     queue.publish(rabbit_droppings.Message("bar"))
     self.rabbit.disconnect()
     self.assertEquals(captive_queue.read().body, "foo")
     self.assertEquals(captive_queue.read().body, "bar")
     self.assertEquals(captive_queue.read(), None)
Esempio n. 2
0
 def test_write_attributes(self):
     captive_queue = self.captive_rabbit.make_queue()
     queue = self.rabbit.queue(captive_queue.name)
     message = rabbit_droppings.Message()
     message.body = "body"
     now = math.floor(time.time())
     message.properties = {
         'content_type': 'text/plain',
         'content_encoding': '8BIT',
         'headers': {
             'foo': 'bar'
         },
         'delivery_mode': 2,
         'priority': 0,
         'correlation_id': 'abc123',
         'reply_to': 'reply_queue',
         'expiration': '12345678',
         'message_id': 'def456',
         'timestamp': now,
         'type': 'test_message',
         'user_id': 'guest',
         'app_id': 'foo.py',
         'cluster_id': 'cluster1',
     }
     queue.publish(message)
     self.rabbit.disconnect()
     message = captive_queue.read()
     self.assertEquals(message.body, "body")
     self.assertEquals(message.properties.content_type, 'text/plain')
     self.assertEquals(message.properties.content_encoding, '8BIT')
     self.assertEquals(message.properties.headers, {'foo': 'bar'})
     self.assertEquals(message.properties.delivery_mode, 2)
     self.assertEquals(message.properties.priority, 0)
     self.assertEquals(message.properties.correlation_id, 'abc123')
     self.assertEquals(message.properties.reply_to, 'reply_queue')
     self.assertEquals(message.properties.expiration, '12345678')
     self.assertEquals(message.properties.message_id, 'def456')
     self.assertEquals(message.properties.timestamp, now)
     self.assertEquals(message.properties.type, 'test_message')
     self.assertEquals(message.properties.user_id, 'guest')
     self.assertEquals(message.properties.app_id, 'foo.py')
     self.assertEquals(message.properties.cluster_id, 'cluster1')
Esempio n. 3
0
 def test_to_pika_message(self):
     now = time.time()
     delivery_info = {'delivery_tag': 'deltag'}
     properties = {
         'content_type': 'text/plain',
         'content_encoding': '8BIT',
         'headers': {
             'foo': 'bar'
         },
         'delivery_mode': 2,
         'priority': 0,
         'correlation_id': 'abc123',
         'reply_to': 'reply_queue',
         'expiration': 12345678,
         'message_id': 'def456',
         'timestamp': now,
         'type': 'test_message',
         'user_id': 'guest',
         'app_id': 'foo.py',
         'cluster_id': 'cluster1',
     }
     body = 'Your ad in this spot'
     message = rabbit_droppings.Message(body, delivery_info, properties)
     pika_message = message.to_pika_message()
     self.assertEqual(pika_message.body, 'Your ad in this spot')
     self.assertEqual(pika_message.properties.content_type, 'text/plain')
     self.assertEqual(pika_message.properties.content_encoding, '8BIT')
     self.assertEqual(pika_message.properties.headers, {'foo': 'bar'})
     self.assertEqual(pika_message.properties.delivery_mode, 2)
     self.assertEqual(pika_message.properties.priority, 0)
     self.assertEqual(pika_message.properties.correlation_id, 'abc123')
     self.assertEqual(pika_message.properties.reply_to, 'reply_queue')
     self.assertEqual(pika_message.properties.expiration, 12345678)
     self.assertEqual(pika_message.properties.message_id, 'def456')
     self.assertEqual(pika_message.properties.timestamp, now)
     self.assertEqual(pika_message.properties.type, 'test_message')
     self.assertEqual(pika_message.properties.user_id, 'guest')
     self.assertEqual(pika_message.properties.app_id, 'foo.py')
     self.assertEqual(pika_message.properties.cluster_id, 'cluster1')
     self.assertEqual(pika_message.delivery_info.delivery_tag, 'deltag')
Esempio n. 4
0
 def test_to_pika_message_when_empty(self):
     delivery_info = {}
     properties = {}
     body = 'Your ad in this spot'
     message = rabbit_droppings.Message(body, delivery_info, properties)
     pika_message = message.to_pika_message()
     self.assertEqual(pika_message.body, 'Your ad in this spot')
     self.assertEqual(pika_message.properties.content_type, None)
     self.assertEqual(pika_message.properties.content_encoding, None)
     self.assertEqual(pika_message.properties.headers, None)
     self.assertEqual(pika_message.properties.delivery_mode, None)
     self.assertEqual(pika_message.properties.priority, None)
     self.assertEqual(pika_message.properties.correlation_id, None)
     self.assertEqual(pika_message.properties.reply_to, None)
     self.assertEqual(pika_message.properties.expiration, None)
     self.assertEqual(pika_message.properties.message_id, None)
     self.assertEqual(pika_message.properties.timestamp, None)
     self.assertEqual(pika_message.properties.type, None)
     self.assertEqual(pika_message.properties.user_id, None)
     self.assertEqual(pika_message.properties.app_id, None)
     self.assertEqual(pika_message.properties.cluster_id, None)
     self.assertEqual(pika_message.delivery_info.delivery_tag, None)
Esempio n. 5
0
 def make_message(self, body):
     message = rabbit_droppings.Message()
     message.body = body
     return message