示例#1
0
    def test_on_redis_errors_raises_RedisError(self, Queue):
        """On Redis connection errors, exceptions subclasses of `RedisError` will be raised."""
        Queue.all.side_effect = RedisError('Connection error')

        with self.assertRaises(RedisError):
            get_jobs_by_queue()

        Queue.all.assert_called_once_with()
示例#2
0
    def test_passing_custom_Queue_class(self, Queue):
        """Test passing a custom `Queue` class."""
        queue_class = Mock()
        queue_class.all.return_value = []

        get_jobs_by_queue(queue_class)

        Queue.all.assert_not_called()
        queue_class.all.assert_called_once_with()
示例#3
0
    def test_return_value_without_any_queues_available(self, Queue):
        """If there are no queues, an empty dict must be returned."""
        Queue.all.return_value = []

        jobs = get_jobs_by_queue()

        Queue.all.assert_called_once_with()
        self.assertEqual(jobs, {})
示例#4
0
    def test_return_value_with_queues_available(self, Queue, get_queue_jobs):
        """On success a dict of the queue names and their jobs dicts must be returned."""
        q_default = Mock()
        q_default.configure_mock(name='default')
        q_default_jobs = {
            JobStatus.QUEUED: 2,
            JobStatus.STARTED: 3,
            JobStatus.FINISHED: 15,
            JobStatus.FAILED: 5,
            JobStatus.DEFERRED: 1,
            JobStatus.SCHEDULED: 4
        }

        q_high = Mock()
        q_high.configure_mock(name='high')
        q_high_jobs = {
            JobStatus.QUEUED: 10,
            JobStatus.STARTED: 4,
            JobStatus.FINISHED: 25,
            JobStatus.FAILED: 22,
            JobStatus.DEFERRED: 5,
            JobStatus.SCHEDULED: 1
        }

        Queue.all.return_value = [q_default, q_high]

        get_queue_jobs.side_effect = [q_default_jobs, q_high_jobs]

        jobs = get_jobs_by_queue()

        Queue.all.assert_called_once_with()

        get_queue_jobs.assert_has_calls(
            # The Queue class is also passed
            [call('default', Queue),
             call('high', Queue)])

        self.assertEqual(jobs, {
            'default': q_default_jobs,
            'high': q_high_jobs
        })