Esempio n. 1
0
    def test_passing_custom_Worker_class(self, Worker):
        """Test passing a custom `Worker` class."""
        worker_class = Mock()
        worker_class.all.return_value = []

        get_workers_stats(worker_class)

        Worker.all.assert_not_called()
        worker_class.all.assert_called_once_with()
Esempio n. 2
0
    def test_returns_worker_stats(self, Worker):
        """When there are workers, a list of worker info dicts must be returned."""
        worker_one = Mock()
        worker_one.configure_mock(
            **{
                'name': 'worker_one',
                'queue_names.return_value': ['default'],
                'get_state.return_value': 'idle'
            })

        worker_two = Mock()
        worker_two.configure_mock(
            **{
                'name': 'worker_two',
                'queue_names.return_value': ['high', 'default', 'low'],
                'get_state.return_value': 'busy'
            })

        Worker.all.return_value = [worker_one, worker_two]

        workers = get_workers_stats()

        Worker.all.assert_called_once_with()

        self.assertEqual(workers, [{
            'name': 'worker_one',
            'queues': ['default'],
            'state': 'idle'
        }, {
            'name': 'worker_two',
            'queues': ['high', 'default', 'low'],
            'state': 'busy'
        }])
Esempio n. 3
0
    def test_returns_empty_list_without_workers(self, Worker):
        """Without any available workers an empty list must be returned."""
        Worker.all.return_value = []

        workers = get_workers_stats()

        Worker.all.assert_called_once_with()

        self.assertEqual(workers, [])
Esempio n. 4
0
    def test_on_redis_errors_raises_RedisError(self, Worker):
        """On Redis connection errors, exceptions subclasses of `RedisError` will be raised."""
        Worker.all.side_effect = RedisError('Connection error')

        with self.assertRaises(RedisError):
            get_workers_stats()