def test_process(self): deployment = self.mox.CreateMockAnything() raw = self.mox.CreateMockAnything() message = self.mox.CreateMockAnything() consumer = worker.NovaConsumer('test', None, deployment, True, {}) routing_key = 'monitor.info' message.delivery_info = {'routing_key': routing_key} body_dict = {u'key': u'value'} message.body = json.dumps(body_dict) self.mox.StubOutWithMock(views, 'process_raw_data', use_mock_anything=True) args = (routing_key, body_dict) views.process_raw_data(deployment, args, json.dumps(args))\ .AndReturn(raw) message.ack() self.mox.StubOutWithMock(views, 'post_process') views.post_process(raw, body_dict) self.mox.StubOutWithMock(consumer, '_check_memory', use_mock_anything=True) consumer._check_memory() self.mox.ReplayAll() consumer._process(message) self.assertEqual(consumer.processed, 1) self.mox.VerifyAll()
def _process(self, message): routing_key = message.delivery_info['routing_key'] body = str(message.body) args = (routing_key, json.loads(body)) asJson = json.dumps(args) # save raw and ack the message raw = views.process_raw_data(self.deployment, args, asJson) if raw: self.processed += 1 message.ack() views.post_process(raw, args[1]) self._check_memory()