예제 #1
0
 def test_worker_3(self):
     config = MagicMock()
     tube = MagicMock()
     tube.opt = {'tube': 'tube_name'}
     task = MagicMock()
     pri = 'pri'
     task.meta = MagicMock(return_value={'pri': pri})
     task.ack = MagicMock(return_value=None)
     task.task_id = MagicMock(return_value=1)
     tube.take = MagicMock(return_value=task)
     with patch('lib.worker.get_tube', MagicMock(return_value=tube)):
         with patch.object(logger, 'info', return_type=None) as mock_logger:
             with patch('lib.worker.os.path.exists', MagicMock(side_effect=(True, True,False))):
                 with patch('lib.worker.get_redirect_history_from_task', MagicMock(return_value=None)):
                     worker(config, 1)
     task.ack.assert_called_with()
     assert not tube.put.called
예제 #2
0
 def test_worker_2(self):
     config = MagicMock()
     tube = MagicMock()
     tube.opt = {'tube': 'tube_name'}
     task = MagicMock()
     pri = 'pri'
     task.meta = MagicMock(return_value={'pri': pri})
     task.ack = MagicMock(return_value=None)
     task.task_id = MagicMock(return_value=1)
     tube.take = MagicMock(return_value=task)
     data = []
     with patch('lib.worker.get_tube', MagicMock(return_value=tube)):
         with patch.object(logger, 'info', return_type=None):
             with patch('lib.worker.os.path.exists', MagicMock(side_effect=(True, False))):
                 with patch('lib.worker.get_redirect_history_from_task', MagicMock(return_value=(True, data))):
                     worker(config, 1)
     tube.put.assert_called_once_with(data, delay=config.RECHECK_DELAY, pri=pri)
     task.ack.assert_called_once_with()
예제 #3
0
 def test_worker_5(self):
     config = MagicMock()
     tube = MagicMock()
     tube.opt = {'tube': 'tube_name'}
     task = MagicMock()
     pri = 'pri'
     task.meta = MagicMock(return_value={'pri': pri})
     task.ack = MagicMock(side_effect=DatabaseError)
     task.task_id = MagicMock(return_value=1)
     tube.take = MagicMock(return_value=task)
     data = []
     with patch('lib.worker.get_tube', MagicMock(return_value=tube)):
         with patch.object(logger, 'info', return_type=None) as mock_logger:
             with patch('lib.worker.os.path.exists', MagicMock(side_effect=(True, False))):
                 with patch('lib.worker.get_redirect_history_from_task', MagicMock(return_value=(True, data))):
                     worker(config, 1)
     task.ack.assert_called_once_with()
     mock_logger.assert_has_calls([call('Task ack fail'), call('Parent is dead. exiting')])
예제 #4
0
 def test_worker_1(self):
     config = MagicMock()
     tube = MagicMock()
     tube.opt = {'tube': 'tube_name'}
     tube.take = MagicMock(return_value=None)
     with patch('lib.worker.get_tube', MagicMock(return_value=tube)):
         with patch.object(logger, 'info', return_type=None) as mock_logger:
             with patch('lib.worker.os.path.exists', MagicMock(side_effect=(True, False))):
                 worker(config, 1)
     mock_logger.assert_has_calls([
         call(u'Connected to input queue server on {host}:{port} space #{space}. name={name}'.format(
             host=tube.queue.host,
             port=tube.queue.port,
             space=tube.queue.space,
             name=tube.opt['tube']
         )),
         call(u'Connected to output queue server on {host}:{port} space #{space} name={name}.'.format(
             host=tube.queue.host,
             port=tube.queue.port,
             space=tube.queue.space,
             name=tube.opt['tube']
         )),
         call('Parent is dead. exiting')
     ])