def listen_and_print(queue_name, connection_details, queue_options): callback = Queue.print_body daemon = Daemon(connection_details) daemon.add_handler(queue_name, callback, timeout=None, limit=None, finish_on_empty=True, finished_callback=None, queue_options=queue_options) daemon.run()
class DaemonTest(unittest.TestCase): queue_params = {"host":"localhost"} def setUp(self): self._daemon = Daemon(self.queue_params) def test_add_handler(self): queue_name = 'testy' callback = test_callback self._daemon.add_handler(queue_name, callback) self.assertEqual(len(self._daemon._handlers), 1) def test_run_hits_receive(self): queue_name = 'testy' callback = test_callback mock_receive = mock.Mock() self._daemon.add_handler(queue_name, callback, limit=1, timeout=1) self._daemon._receive = mock_receive self._daemon.run() mock_receive.assert_called_once_with( finished_callback=None, exchange_name=None, queue_name='testy', callback=test_callback, finish_on_empty=False, limit=1, timeout=1, queue_options={} ) def test_run_calls_queue_receive(self): queue_name = 'testy' callback = test_callback mock_queue = mock.Mock(Queue) self._daemon.add_handler(queue_name, callback, limit=1, timeout=1) self._daemon._queue_class = mock.Mock self._daemon._run_once = True self._daemon.run() mock_queue.receive.assert_called_once()
def setUp(self): self._daemon = Daemon(self.queue_params)