def test_refresh_cache_fmn_message(self, mock_find_recipients): """Assert messages with an '.fmn.' topic result in a message to workers.""" fmn_consumer = consumer.FMNConsumer(self.hub) fmn_consumer.autocreate = False message = { 'topic': 'com.example.fmn.topic', 'body': { 'msg_id': '12', 'msg': { 'openid': 'jcline.id.fedoraproject.org' }, 'topic': 'com.example.topic', } } fmn_consumer.work(self.sess, message) self.assertEqual( mock_find_recipients.apply_async.call_args_list[0][0][0], ({ 'topic': 'fmn.internal.refresh_cache', 'body': 'jcline.id.fedoraproject.org' }, ), ) self.assertEqual( mock_find_recipients.apply_async.call_args_list[0][1], dict(exchange='fmn.tasks.reload_cache', routing_key=self.config['celery']['task_default_queue']), )
def test_default_topic(self): """Assert the default topic for the FMN consumer is everything.""" fmn_consumer = consumer.FMNConsumer(self.hub) self.assertEqual(['*'], fmn_consumer.topic) self.hub.subscribe.assert_called_once_with(b'*', fmn_consumer._consume_json)
def test_custom_topics(self): """Assert the default topic for the FMN consumer is everything.""" self.config['fmn.topics'] = [b'my.custom.topic'] with mock.patch.dict(consumer.config.app_conf, self.config): fmn_consumer = consumer.FMNConsumer(self.hub) self.assertEqual([b'my.custom.topic'], fmn_consumer.topic) self.hub.subscribe.assert_called_once_with(b'my.custom.topic', fmn_consumer._consume_json)
def test_refresh_cache_auto_create(self, mock_find_recipients): """Assert messages with an '.fmn.' topic result in a message to workers.""" fmn_consumer = consumer.FMNConsumer(self.hub) fmn_consumer.autocreate = True message = { 'topic': 'com.example.topic', 'body': { 'msg_id': '12', 'topic': 'com.example.topic', } } fmn_consumer.work(self.sess, message) self.assertEqual( mock_find_recipients.apply_async.call_args_list[0][0][0], ({ 'topic': 'fmn.internal.refresh_cache', 'body': 'jcline.id.fedoraproject.org' }, ), ) self.assertEqual( mock_find_recipients.apply_async.call_args_list[0][1], dict(exchange='fmn.tasks.reload_cache'), )
def test_heat_cache(self, mock_heat): """Assert a task is dispatched to heat the cache on startup.""" consumer.FMNConsumer(self.hub) mock_heat.apply_async.assert_called_once_with()