def test_done_with_processed_tasks_successed(self):
        m_task = mock.Mock()
        m_task.task_method = mock.Mock()

        notification_pusher.done_with_processed_tasks(self._m_task_queue(mock.Mock(return_value=(m_task, 'task_method'))))

        self.assertEqual(m_task.task_method.call_count, 1, "Expected only one call")
    def test_done_with_processed_tasks_queue_is_empty(self):
        m_task_queue = self._m_task_queue(mock.Mock(side_effect=notification_pusher.gevent_queue.Empty))

        try:
            notification_pusher.done_with_processed_tasks(m_task_queue)
        except gevent_queue.Empty:
            self.fail("gevent_queue.Empty exception must be caught")
 def test_done_with_processed_tasks_all_well(self):
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value=1)
     task = mock.Mock()
     task_queue.get_nowait = mock.Mock(return_value=(task, "some_method"))
     notification_pusher.done_with_processed_tasks(task_queue)
     self.assertTrue(task.some_method.called)
    def test_done_with_processed_tasks_empty(self):
        task_queue = mock.Mock()
        task_queue.qsize = mock.Mock(return_value = 1)
        task_queue.get_nowait = mock.Mock(side_effect = notification_pusher.gevent_queue.Empty)
        mock.patch('source.notification_pusher.logger.debug', mock.Mock())
        try:
            notification_pusher.done_with_processed_tasks(task_queue)
        except notification_pusher.gevent_queue.Empty:
			self.fail()
 def test_done_with_processed_tasks_suc(self):
     task = mock.Mock()
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value = 1)
     task_queue.get_nowait = mock.Mock(return_value = (task, 'task_method'))
     logger = mock.MagicMock()
     with mock.patch('notification_pusher.logger', logger):
         notification_pusher.done_with_processed_tasks(task_queue)
     self.assertFalse(logger.exception.called)
Пример #6
0
    def test_task_queue_get_nowait_raised_exception(self):
        task_queue_size = 4
        task_queue = mock.Mock()
        task_queue.qsize = mock.Mock(return_value=task_queue_size)
        task_queue.get_nowait = mock.Mock(side_effect=gevent_queue.Empty)
        with mock.patch('source.notification_pusher.logger', mock.Mock()):
            notification_pusher.done_with_processed_tasks(task_queue)

        self.assertEqual(1, task_queue.get_nowait.call_count)
Пример #7
0
 def test_done_with_processed_tasks_suc(self):
     task = mock.Mock()
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value=1)
     task_queue.get_nowait = mock.Mock(return_value=(task, 'task_method'))
     logger = mock.MagicMock()
     with mock.patch('notification_pusher.logger', logger):
         notification_pusher.done_with_processed_tasks(task_queue)
     self.assertFalse(logger.exception.called)
    def test_done_with_processed_tasks(self):
        queue_m = mock.Mock()
        task = mock.Mock()
        queue_m.get_nowait = mock.Mock(return_value=(task, 'test_method'))
        queue_m.qsize = mock.Mock(return_value=1)

        notification_pusher.done_with_processed_tasks(queue_m)

        self.assertTrue(task.test_method.called, "task's method not called")
 def test_done_with_processed_tasks_err(self):
     task = mock.Mock()
     task.task_method = mock.Mock(side_effect=tarantool.DatabaseError())
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value = 1)
     task_queue.get_nowait = mock.Mock(return_value=(task, 'task_method'))
     try:
         notification_pusher.done_with_processed_tasks(task_queue)
     except tarantool.DatabaseError:
         self.fail()
 def test_done_with_processed_tasks_gevent_queue_empty(self):
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value=1)
     task_queue.get_nowait = mock.Mock(side_effect=[gevent_queue.Empty()])
     logger = mock.MagicMock()
     task = mock.Mock()
     with mock.patch('source.notification_pusher.logger', logger):
         notification_pusher.done_with_processed_tasks(task_queue)
     self.assertFalse(logger.exception.called)
     self.assertFalse(task.some_method.called)
 def test_done_with_processed_tasks_empty_queue(self):
     """
     Пустая очередь
     """
     task_queue = gevent_queue.Queue()
     logger = mock.Mock()
     with mock.patch('source.notification_pusher.logger', logger):
         notification_pusher.done_with_processed_tasks(task_queue)
     empty_msg = notification_pusher.empty_queue_msg
     assert mock.call.debug(empty_msg) in logger.mock_calls
Пример #12
0
 def test_done_with_processed_tasks_err(self):
     task = mock.Mock()
     task.task_method = mock.Mock(side_effect=tarantool.DatabaseError())
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value=1)
     task_queue.get_nowait = mock.Mock(return_value=(task, 'task_method'))
     try:
         notification_pusher.done_with_processed_tasks(task_queue)
     except tarantool.DatabaseError:
         self.fail()
Пример #13
0
 def test_done_with_processed_tasks_empty(self):
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value=1)
     task_queue.get_nowait = mock.Mock(
         side_effect=notification_pusher.gevent_queue.Empty)
     mock.patch('source.notification_pusher.logger.debug', mock.Mock())
     try:
         notification_pusher.done_with_processed_tasks(task_queue)
     except notification_pusher.gevent_queue.Empty:
         self.fail()
 def test_done_with_processed_tasks_getattr_database_error(self):
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value=1)
     task = mock.Mock()
     task_queue.get_nowait = mock.Mock(return_value=(task, 'some_method'))
     logger = mock.MagicMock()
     import tarantool
     task.some_method = mock.Mock(side_effect=tarantool.DatabaseError())
     with mock.patch('source.notification_pusher.logger', logger):
         notification_pusher.done_with_processed_tasks(task_queue)
     self.assertTrue(logger.exception.called)
    def test_done_with_processed_tasks_queue_empty(self):
        from gevent import queue as gevent_queue

        queue_m = mock.Mock()
        queue_m.get_nowait = mock.Mock(side_effect=[gevent_queue.Empty()])
        queue_m.qsize = mock.Mock(return_value=1)

        try:
            notification_pusher.done_with_processed_tasks(queue_m)
        except gevent_queue.Empty:
            self.fail('gevent_queue.Empty raised from notification_pusher')
 def test_done_with_processed_tasks_with_task_with_attr(self):
     """
     Все хорошо
     """
     task = mock.MagicMock(name="task")
     task_queue = gevent_queue.Queue()
     task_queue.put((task, "action"))
     logger = mock.MagicMock()
     with mock.patch('source.notification_pusher.logger', logger):
         notification_pusher.done_with_processed_tasks(task_queue)
     self.assertFalse(logger.exception.called)
    def test_done_with_processed_tasks_db_error(self):
        import tarantool

        m_task = mock.Mock()
        m_task.task_method = mock.Mock(side_effect=tarantool.DatabaseError())

        try:
            notification_pusher.done_with_processed_tasks(self._m_task_queue(mock.Mock(return_value=(m_task,
                                                                                                     'task_method'))))
        except tarantool.DatabaseError:
            self.fail("DatabaseError exception must be caught")
Пример #18
0
 def test_task_queue_get_nowait_didnt_raise_exception(self):
     action_name = 'method'
     task = mock.Mock()
     task.method = mock.Mock()
     task_action_name = (task, action_name)
     task_queue_size = 4
     task_queue = mock.Mock()
     task_queue.qsize = mock.Mock(return_value=task_queue_size)
     task_queue.get_nowait = mock.Mock(return_value=task_action_name)
     with mock.patch('source.notification_pusher.logger', mock.Mock()):
         notification_pusher.done_with_processed_tasks(task_queue)
     self.assertEqual(task_queue_size, task_queue.get_nowait.call_count)
    def test_done_with_processed_tasks_db_exception_handling(self):
        queue_m = mock.Mock()
        task = mock.Mock()
        queue_m.get_nowait = mock.Mock(return_value=(task, 'test_method'))
        queue_m.qsize = mock.Mock(return_value=1)

        import tarantool

        task.test_method = mock.Mock(side_effect=tarantool.DatabaseError())

        try:
            notification_pusher.done_with_processed_tasks(queue_m)
        except tarantool.DatabaseError:
            self.fail('tarantool.DatabaseError raised from notification_pusher')
    def test_done_with_processed_tasks_with_task_without_attr(self):
        """
        Не удалось вызвать getattr у задачи
        """
        task = mock.MagicMock(name="task")
        action_name = "action"
        task_queue = gevent_queue.Queue()
        task_queue.put((task, action_name))
        logger = mock.Mock()
        e = tarantool.DatabaseError("Error")
        task.action = mock.Mock(side_effect=e)
        with mock.patch('source.notification_pusher.logger', logger):
            notification_pusher.done_with_processed_tasks(task_queue)

        assert mock.call.exception(e) in logger.method_calls
Пример #21
0
    def test_task_has_no_method(self):
        action_name = 'method'
        task = mock.Mock()
        task.method = mock.Mock(side_effect=tarantool.DatabaseError)
        task_action_name = (task, action_name)
        task_queue_size = 1
        task_queue = mock.Mock()
        task_queue.qsize = mock.Mock(return_value=task_queue_size)
        task_queue.get_nowait = mock.Mock(return_value=task_action_name)

        with mock.patch('source.notification_pusher.logger', mock.Mock()):
            with mock.patch('source.notification_pusher.logger.exception',
                            mock.Mock()) as logger_exception_mock:
                notification_pusher.done_with_processed_tasks(task_queue)
        self.assertEqual(task_queue_size, logger_exception_mock.call_count)