def test_factory_should_return_nova_notification_for_nova_exchange(self): body = {} deployment = "1" json = "{}" routing_key = "monitor.info" self.mox.StubOutWithMock(notification, 'NovaNotification') notification.NovaNotification(body, deployment, routing_key, json) self.mox.ReplayAll() notification.notification_factory(body, deployment, routing_key, json, 'nova') self.mox.VerifyAll()
def test_factory_should_return_nova_notification_for_nova_exchange( self): body = {} deployment = "1" json = "{}" routing_key = "monitor.info" self.mox.StubOutWithMock(notification, 'NovaNotification') notification.NovaNotification(body, deployment, routing_key, json) self.mox.ReplayAll() notification.notification_factory(body, deployment, routing_key, json, 'nova') self.mox.VerifyAll()
def process_raw_data(deployment, args, json_args, exchange): """This is called directly by the worker to add the event to the db.""" db.reset_queries() routing_key, body = args notif = notification.notification_factory(body, deployment, routing_key, json_args, exchange) raw = notif.save() return raw, notif
def test_process_raw_data_old_timestamp(self): deployment = self.mox.CreateMockAnything() when = '2013-1-25T13:38:23.123' dict = { '_context_timestamp': when, } routing_key = 'monitor.info' args = ('monitor.info', dict) json_args = json.dumps(args[1]) mock_notification = self.mox.CreateMockAnything() mock_notification.save() self.mox.StubOutWithMock(notification, 'notification_factory') exchange = 'nova' notification.notification_factory(dict, deployment, routing_key, json_args, exchange).AndReturn(mock_notification) self.mox.ReplayAll() views.process_raw_data(deployment, args, json_args, exchange) self.mox.VerifyAll()
def test_process_raw_data(self): deployment = self.mox.CreateMockAnything() when = '2013-1-25 13:38:23.123' dict = { 'timestamp': when, } routing_key = 'monitor.info' args = (routing_key, dict) json_args = json.dumps(args) mock_record = self.mox.CreateMockAnything() mock_notification = self.mox.CreateMockAnything() mock_notification.save().AndReturn(mock_record) self.mox.StubOutWithMock(notification, 'notification_factory') exchange = 'nova' notification.notification_factory( dict, deployment, routing_key, json_args, exchange).AndReturn(mock_notification) self.mox.ReplayAll() self.assertEquals( views.process_raw_data(deployment, args, json_args, exchange), (mock_record, mock_notification)) self.mox.VerifyAll()
def test_process_raw_data(self): deployment = self.mox.CreateMockAnything() when = '2013-1-25 13:38:23.123' dict = { 'timestamp': when, } routing_key = 'monitor.info' args = (routing_key, dict) json_args = json.dumps(args) mock_record = self.mox.CreateMockAnything() mock_notification = self.mox.CreateMockAnything() mock_notification.save().AndReturn(mock_record) self.mox.StubOutWithMock(notification, 'notification_factory') exchange = 'nova' notification.notification_factory(dict, deployment, routing_key, json_args, exchange).AndReturn( mock_notification) self.mox.ReplayAll() self.assertEquals( views.process_raw_data(deployment, args, json_args, exchange), (mock_record, mock_notification)) self.mox.VerifyAll()
def _notification(self, json_message): json_dict = json.loads(json_message) routing_key = json_dict[0] body = json_dict[1] return notification_factory(body, None, routing_key, json_message, 'nova')