예제 #1
0
 def test_get_children(self):
     b = BaseBackend(app=self.app)
     b._get_task_meta_for = Mock()
     b._get_task_meta_for.return_value = {}
     self.assertIsNone(b.get_children('id'))
     b._get_task_meta_for.return_value = {'children': 3}
     self.assertEqual(b.get_children('id'), 3)
예제 #2
0
 def test_mark_as_done__chord(self):
     b = BaseBackend(app=self.app)
     b._store_result = Mock()
     request = Mock(name='request')
     b.on_chord_part_return = Mock()
     b.mark_as_done('id', 10, request=request)
     b.on_chord_part_return.assert_called_with(request, states.SUCCESS, 10)
예제 #3
0
파일: test_base.py 프로젝트: Awingu/celery
 def test_mark_as_revoked__chord(self):
     b = BaseBackend(app=self.app)
     b._store_result = Mock()
     request = Mock(name='request')
     b.on_chord_part_return = Mock()
     b.mark_as_revoked('id', 'revoked', request=request)
     b.on_chord_part_return.assert_called_with(request, states.REVOKED, ANY)
예제 #4
0
 def test_get_children(self):
     b = BaseBackend(app=self.app)
     b._get_task_meta_for = Mock()
     b._get_task_meta_for.return_value = {}
     assert b.get_children('id') is None
     b._get_task_meta_for.return_value = {'children': 3}
     assert b.get_children('id') == 3
예제 #5
0
파일: test_base.py 프로젝트: Awingu/celery
 def test_mark_as_failure__chord(self):
     b = BaseBackend(app=self.app)
     b._store_result = Mock()
     request = Mock(name='request')
     b.on_chord_part_return = Mock()
     exc = KeyError()
     b.mark_as_failure('id', exc, request=request)
     b.on_chord_part_return.assert_called_with(request, states.FAILURE, exc)
예제 #6
0
파일: test_base.py 프로젝트: m4ddav3/celery
 def test_mark_as_revoked__chord(self):
     b = BaseBackend(app=self.app)
     b._store_result = Mock()
     request = Mock(name="request")
     request.errbacks = []
     b.on_chord_part_return = Mock()
     b.mark_as_revoked("id", "revoked", request=request)
     b.on_chord_part_return.assert_called_with(request, states.REVOKED, ANY)
예제 #7
0
파일: test_base.py 프로젝트: celery/celery
    def test_exception_to_python_when_attribute_exception(self):
        b = BaseBackend(app=self.app)
        test_exception = {'exc_type': 'AttributeDoesNotExist',
                          'exc_module': 'celery',
                          'exc_message': ['Raise Custom Message']}

        result_exc = b.exception_to_python(test_exception)
        assert str(result_exc) == 'Raise Custom Message'
예제 #8
0
파일: test_base.py 프로젝트: celery/celery
 def test_mark_as_failure__errback(self):
     b = BaseBackend(app=self.app)
     b._store_result = Mock()
     request = Mock(name='request')
     request.errbacks = [self.errback.subtask(args=[2, 3], immutable=True)]
     exc = KeyError()
     b.mark_as_failure('id', exc, request=request)
     assert self.errback.last_result == 5
예제 #9
0
파일: test_base.py 프로젝트: m4ddav3/celery
class test_as_uri(AppCase):
    def setup(self):
        self.b = BaseBackend(app=self.app, url="sch://*****:*****@hostname.dom")

    def test_as_uri_include_password(self):
        self.assertEqual(self.b.as_uri(True), self.b.url)

    def test_as_uri_exclude_password(self):
        self.assertEqual(self.b.as_uri(), "sch://*****:*****@hostname.dom/")
예제 #10
0
파일: test_base.py 프로젝트: celery/celery
    def test_unregistered_task_can_be_used_as_error_callback(self, mock_group):
        b = BaseBackend(app=self.app)
        b._store_result = Mock()

        request = Mock(name='request')
        request.errbacks = [signature('doesnotexist',
                                      immutable=True)]
        exc = KeyError()
        b.mark_as_failure('id', exc, request=request)
        mock_group.assert_called_once_with(request.errbacks, app=self.app)
예제 #11
0
파일: test_base.py 프로젝트: celery/celery
    def test_exception_to_python_when_type_error(self):
        b = BaseBackend(app=self.app)
        celery.TestParamException = paramexception
        test_exception = {'exc_type': 'TestParamException',
                          'exc_module': 'celery',
                          'exc_message': []}

        result_exc = b.exception_to_python(test_exception)
        del celery.TestParamException
        assert str(result_exc) == "<class 't.unit.backends.test_base.paramexception'>([])"
예제 #12
0
파일: test_base.py 프로젝트: m4ddav3/celery
 def test_chord_error_from_stack_raises(self):
     b = BaseBackend(app=self.app)
     exc = KeyError()
     callback = Mock(name="callback")
     callback.options = {"link_error": []}
     task = self.app.tasks[callback.task] = Mock()
     b.fail_from_current_stack = Mock()
     group = self.patch("celery.group")
     group.side_effect = exc
     b.chord_error_from_stack(callback, exc=ValueError())
     task.backend.fail_from_current_stack.assert_called_with(callback.id, exc=exc)
예제 #13
0
파일: test_base.py 프로젝트: celery/celery
 def test_mark_as_failure__bound_errback(self):
     b = BaseBackend(app=self.app)
     b._store_result = Mock()
     request = Mock(name='request')
     request.errbacks = [
         self.bound_errback.subtask(args=[1], immutable=True)]
     exc = KeyError()
     group = self.patching('celery.backends.base.group')
     b.mark_as_failure('id', exc, request=request)
     group.assert_called_with(request.errbacks, app=self.app)
     group.return_value.apply_async.assert_called_with(
         (request.id, ), parent_id=request.id, root_id=request.root_id)
예제 #14
0
class test_as_uri:

    def setup(self):
        self.b = BaseBackend(
            app=self.app,
            url='sch://*****:*****@hostname.dom'
        )

    def test_as_uri_include_password(self):
        assert self.b.as_uri(True) == self.b.url

    def test_as_uri_exclude_password(self):
        assert self.b.as_uri() == 'sch://*****:*****@hostname.dom/'
예제 #15
0
class test_BaseBackend_interface(AppCase):

    def setup(self):
        self.b = BaseBackend(self.app)

    def test__forget(self):
        with self.assertRaises(NotImplementedError):
            self.b._forget('SOMExx-N0Nex1stant-IDxx-')

    def test_forget(self):
        with self.assertRaises(NotImplementedError):
            self.b.forget('SOMExx-N0nex1stant-IDxx-')

    def test_on_chord_part_return(self):
        self.b.on_chord_part_return(None)

    def test_on_chord_apply(self, unlock='celery.chord_unlock'):
        p, self.app.tasks[unlock] = self.app.tasks.get(unlock), Mock()
        try:
            self.b.on_chord_apply(
                'dakj221', 'sdokqweok',
                result=[self.app.AsyncResult(x) for x in [1, 2, 3]],
            )
            self.assertTrue(self.app.tasks[unlock].apply_async.call_count)
        finally:
            self.app.tasks[unlock] = p
예제 #16
0
파일: test_base.py 프로젝트: celery/celery
    def test_class_based_task_can_be_used_as_error_callback(self, mock_group):
        b = BaseBackend(app=self.app)
        b._store_result = Mock()

        class TaskBasedClass(Task):
            def run(self):
                pass

        TaskBasedClass = self.app.register_task(TaskBasedClass())

        request = Mock(name='request')
        request.errbacks = [TaskBasedClass.subtask(args=[], immutable=True)]
        exc = KeyError()
        b.mark_as_failure('id', exc, request=request)
        mock_group.assert_called_once_with(request.errbacks, app=self.app)
예제 #17
0
파일: test_base.py 프로젝트: celery/celery
    def setup(self):
        self.b = BaseBackend(self.app)

        @self.app.task(shared=False)
        def callback(result):
            pass

        self.callback = callback
예제 #18
0
class test_prepare_exception:

    def setup(self):
        self.b = BaseBackend(self.app)

    def test_unpickleable(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(Unpickleable(1, 2, 'foo'))
        assert isinstance(x, KeyError)
        y = self.b.exception_to_python(x)
        assert isinstance(y, KeyError)

    def test_impossible(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(Impossible())
        assert isinstance(x, UnpickleableExceptionWrapper)
        assert str(x)
        y = self.b.exception_to_python(x)
        assert y.__class__.__name__ == 'Impossible'
        if sys.version_info < (2, 5):
            assert y.__class__.__module__
        else:
            assert y.__class__.__module__ == 'foo.module'

    def test_regular(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(KeyError('baz'))
        assert isinstance(x, KeyError)
        y = self.b.exception_to_python(x)
        assert isinstance(y, KeyError)

    def test_unicode_message(self):
        message = u'\u03ac'
        x = self.b.prepare_exception(Exception(message))
        assert x == {'exc_message': message, 'exc_type': 'Exception'}
예제 #19
0
class test_prepare_exception(AppCase):

    def setup(self):
        self.b = BaseBackend(self.app)

    def test_unpickleable(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(Unpickleable(1, 2, 'foo'))
        self.assertIsInstance(x, KeyError)
        y = self.b.exception_to_python(x)
        self.assertIsInstance(y, KeyError)

    def test_impossible(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(Impossible())
        self.assertIsInstance(x, UnpickleableExceptionWrapper)
        self.assertTrue(str(x))
        y = self.b.exception_to_python(x)
        self.assertEqual(y.__class__.__name__, 'Impossible')
        if sys.version_info < (2, 5):
            self.assertTrue(y.__class__.__module__)
        else:
            self.assertEqual(y.__class__.__module__, 'foo.module')

    def test_regular(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(KeyError('baz'))
        self.assertIsInstance(x, KeyError)
        y = self.b.exception_to_python(x)
        self.assertIsInstance(y, KeyError)
예제 #20
0
    def test_wait_for__on_interval(self):
        self.patching('time.sleep')
        b = BaseBackend(app=self.app)
        b._get_task_meta_for = Mock()
        b._get_task_meta_for.return_value = {'status': states.PENDING}
        callback = Mock(name='callback')
        with pytest.raises(TimeoutError):
            b.wait_for(task_id='1', on_interval=callback, timeout=1)
        callback.assert_called_with()

        b._get_task_meta_for.return_value = {'status': states.SUCCESS}
        b.wait_for(task_id='1', timeout=None)
예제 #21
0
파일: test_base.py 프로젝트: m4ddav3/celery
    def test_wait_for__on_interval(self):
        self.patch("time.sleep")
        b = BaseBackend(app=self.app)
        b._get_task_meta_for = Mock()
        b._get_task_meta_for.return_value = {"status": states.PENDING}
        callback = Mock(name="callback")
        with self.assertRaises(TimeoutError):
            b.wait_for(task_id="1", on_interval=callback, timeout=1)
        callback.assert_called_with()

        b._get_task_meta_for.return_value = {"status": states.SUCCESS}
        b.wait_for(task_id="1", timeout=None)
예제 #22
0
class test_BaseBackend_interface(AppCase):
    def setup(self):
        self.b = BaseBackend(self.app)

    def test__forget(self):
        with self.assertRaises(NotImplementedError):
            self.b._forget("SOMExx-N0Nex1stant-IDxx-")

    def test_forget(self):
        with self.assertRaises(NotImplementedError):
            self.b.forget("SOMExx-N0nex1stant-IDxx-")

    def test_on_chord_part_return(self):
        self.b.on_chord_part_return(None, None, None)

    def test_apply_chord(self, unlock="celery.chord_unlock"):
        self.app.tasks[unlock] = Mock()
        self.b.apply_chord(
            group(app=self.app), (), "dakj221", None, result=[self.app.AsyncResult(x) for x in [1, 2, 3]]
        )
        self.assertTrue(self.app.tasks[unlock].apply_async.call_count)
예제 #23
0
class test_BaseBackend_interface:

    def setup(self):
        self.b = BaseBackend(self.app)

    def test__forget(self):
        with pytest.raises(NotImplementedError):
            self.b._forget('SOMExx-N0Nex1stant-IDxx-')

    def test_forget(self):
        with pytest.raises(NotImplementedError):
            self.b.forget('SOMExx-N0nex1stant-IDxx-')

    def test_on_chord_part_return(self):
        self.b.on_chord_part_return(None, None, None)

    def test_apply_chord(self, unlock='celery.chord_unlock'):
        self.app.tasks[unlock] = Mock()
        self.b.apply_chord(
            group(app=self.app), (), 'dakj221', None,
            result=[self.app.AsyncResult(x) for x in [1, 2, 3]],
        )
        assert self.app.tasks[unlock].apply_async.call_count
예제 #24
0
class test_BaseBackend_interface:

    def setup(self):
        self.b = BaseBackend(self.app)

        @self.app.task(shared=False)
        def callback(result):
            pass

        self.callback = callback

    def test__forget(self):
        with pytest.raises(NotImplementedError):
            self.b._forget('SOMExx-N0Nex1stant-IDxx-')

    def test_forget(self):
        with pytest.raises(NotImplementedError):
            self.b.forget('SOMExx-N0nex1stant-IDxx-')

    def test_on_chord_part_return(self):
        self.b.on_chord_part_return(None, None, None)

    def test_apply_chord(self, unlock='celery.chord_unlock'):
        self.app.tasks[unlock] = Mock()
        header_result_args = (
            uuid(),
            [self.app.AsyncResult(x) for x in range(3)],
        )
        self.b.apply_chord(header_result_args, self.callback.s())
        assert self.app.tasks[unlock].apply_async.call_count

    def test_chord_unlock_queue(self, unlock='celery.chord_unlock'):
        self.app.tasks[unlock] = Mock()
        header_result_args = (
            uuid(),
            [self.app.AsyncResult(x) for x in range(3)],
        )
        body = self.callback.s()

        self.b.apply_chord(header_result_args, body)
        called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
        assert called_kwargs['queue'] == 'testcelery'

        routing_queue = Mock()
        routing_queue.name = "routing_queue"
        self.app.amqp.router.route = Mock(return_value={
            "queue": routing_queue
        })
        self.b.apply_chord(header_result_args, body)
        assert self.app.amqp.router.route.call_args[0][1] == body.name
        called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
        assert called_kwargs["queue"] == "routing_queue"

        self.b.apply_chord(header_result_args, body.set(queue='test_queue'))
        called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
        assert called_kwargs['queue'] == 'test_queue'

        @self.app.task(shared=False, queue='test_queue_two')
        def callback_queue(result):
            pass

        self.b.apply_chord(header_result_args, callback_queue.s())
        called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
        assert called_kwargs['queue'] == 'test_queue_two'

        with self.Celery() as app2:
            @app2.task(name='callback_different_app', shared=False)
            def callback_different_app(result):
                pass

            callback_different_app_signature = self.app.signature('callback_different_app')
            self.b.apply_chord(header_result_args, callback_different_app_signature)
            called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
            assert called_kwargs['queue'] == 'routing_queue'

            callback_different_app_signature.set(queue='test_queue_three')
            self.b.apply_chord(header_result_args, callback_different_app_signature)
            called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
            assert called_kwargs['queue'] == 'test_queue_three'
예제 #25
0
 def test_add_to_chord_interface(self):
     b = BaseBackend(self.app)
     with pytest.raises(NotImplementedError):
         b.add_to_chord('group_id', 'sig')
예제 #26
0
 def setup(self):
     self.b = BaseBackend(app=self.app, url='sch://*****:*****@hostname.dom')
예제 #27
0
 def test_should_retry_exception(self):
     assert not BaseBackend(app=self.app).exception_safe_to_retry(
         Exception("test"))
예제 #28
0
 def test_forget_interface(self):
     b = BaseBackend(self.app)
     with pytest.raises(NotImplementedError):
         b.forget('foo')
예제 #29
0
 def test_is_cached(self):
     b = BaseBackend(app=self.app, max_cached_results=1)
     b._cache['foo'] = 1
     self.assertTrue(b.is_cached('foo'))
     self.assertFalse(b.is_cached('false'))
예제 #30
0
from celery.tests.utils import AppCase, Case


class wrapobject(object):
    def __init__(self, *args, **kwargs):
        self.args = args


if sys.version_info >= (3, 0):
    Oldstyle = None
else:
    Oldstyle = types.ClassType('Oldstyle', (), {})
Unpickleable = subclass_exception('Unpickleable', KeyError, 'foo.module')
Impossible = subclass_exception('Impossible', object, 'foo.module')
Lookalike = subclass_exception('Lookalike', wrapobject, 'foo.module')
b = BaseBackend()


class test_serialization(Case):
    def test_create_exception_cls(self):
        self.assertTrue(serialization.create_exception_cls('FooError', 'm'))
        self.assertTrue(
            serialization.create_exception_cls('FooError', 'm', KeyError))


class test_BaseBackend_interface(Case):
    def test__forget(self):
        with self.assertRaises(NotImplementedError):
            b._forget('SOMExx-N0Nex1stant-IDxx-')

    def test_forget(self):
예제 #31
0
 def setup(self):
     self.b = BaseBackend(self.app)
예제 #32
0
 def __init__(self, *args, **kwargs):
     BaseBackend.__init__(self, *args, **kwargs)
     self._data = {'can-delete': {'result': 'foo'}}
예제 #33
0
 def test_save_group(self):
     b = BaseBackend(self.app)
     b._save_group = Mock()
     b.save_group('foofoo', 'xxx')
     b._save_group.assert_called_with('foofoo', 'xxx')
예제 #34
0
 def test_add_to_chord_interface(self):
     b = BaseBackend(self.app)
     with pytest.raises(NotImplementedError):
         b.add_to_chord('group_id', 'sig')
예제 #35
0
 def test_exception_to_python_when_None(self):
     b = BaseBackend(app=self.app)
     assert b.exception_to_python(None) is None
예제 #36
0
 def test_is_cached(self):
     b = BaseBackend(app=self.app, max_cached_results=1)
     b._cache['foo'] = 1
     assert b.is_cached('foo')
     assert not b.is_cached('false')
예제 #37
0
 def test_is_cached(self):
     b = BaseBackend(app=self.app, max_cached_results=1)
     b._cache['foo'] = 1
     assert b.is_cached('foo')
     assert not b.is_cached('false')
예제 #38
0
 def test_exception_to_python_when_None(self):
     b = BaseBackend(app=self.app)
     assert b.exception_to_python(None) is None
예제 #39
0
 def test_forget_interface(self):
     b = BaseBackend(self.app)
     with pytest.raises(NotImplementedError):
         b.forget('foo')
예제 #40
0
class test_prepare_exception:
    def setup(self):
        self.b = BaseBackend(self.app)

    def test_unpickleable(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(Unpickleable(1, 2, 'foo'))
        assert isinstance(x, KeyError)
        y = self.b.exception_to_python(x)
        assert isinstance(y, KeyError)

    def test_json_exception_arguments(self):
        self.b.serializer = 'json'
        x = self.b.prepare_exception(Exception(object))
        assert x == {
            'exc_message':
            serialization.ensure_serializable((object, ), self.b.encode),
            'exc_type':
            Exception.__name__,
            'exc_module':
            Exception.__module__
        }
        y = self.b.exception_to_python(x)
        assert isinstance(y, Exception)

    @pytest.mark.skipif(sys.version_info < (3, 3),
                        reason='no qualname support')
    def test_json_exception_nested(self):
        self.b.serializer = 'json'
        x = self.b.prepare_exception(objectexception.Nested('msg'))
        assert x == {
            'exc_message': ('msg', ),
            'exc_type': 'objectexception.Nested',
            'exc_module': objectexception.Nested.__module__
        }
        y = self.b.exception_to_python(x)
        assert isinstance(y, objectexception.Nested)

    def test_impossible(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(Impossible())
        assert isinstance(x, UnpickleableExceptionWrapper)
        assert str(x)
        y = self.b.exception_to_python(x)
        assert y.__class__.__name__ == 'Impossible'
        if sys.version_info < (2, 5):
            assert y.__class__.__module__
        else:
            assert y.__class__.__module__ == 'foo.module'

    def test_regular(self):
        self.b.serializer = 'pickle'
        x = self.b.prepare_exception(KeyError('baz'))
        assert isinstance(x, KeyError)
        y = self.b.exception_to_python(x)
        assert isinstance(y, KeyError)

    def test_unicode_message(self):
        message = u'\u03ac'
        x = self.b.prepare_exception(Exception(message))
        assert x == {
            'exc_message': (message, ),
            'exc_type': Exception.__name__,
            'exc_module': Exception.__module__
        }
예제 #41
0
class test_BaseBackend_interface:
    def setup(self):
        self.b = BaseBackend(self.app)

        @self.app.task(shared=False)
        def callback(result):
            pass

        self.callback = callback

    def test__forget(self):
        with pytest.raises(NotImplementedError):
            self.b._forget('SOMExx-N0Nex1stant-IDxx-')

    def test_forget(self):
        with pytest.raises(NotImplementedError):
            self.b.forget('SOMExx-N0nex1stant-IDxx-')

    def test_on_chord_part_return(self):
        self.b.on_chord_part_return(None, None, None)

    def test_apply_chord(self, unlock='celery.chord_unlock'):
        self.app.tasks[unlock] = Mock()
        header_result = self.app.GroupResult(
            uuid(),
            [self.app.AsyncResult(x) for x in range(3)],
        )
        self.b.apply_chord(header_result, self.callback.s())
        assert self.app.tasks[unlock].apply_async.call_count

    def test_chord_unlock_queue(self, unlock='celery.chord_unlock'):
        self.app.tasks[unlock] = Mock()
        header_result = self.app.GroupResult(
            uuid(),
            [self.app.AsyncResult(x) for x in range(3)],
        )
        body = self.callback.s()

        self.b.apply_chord(header_result, body)
        called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
        assert called_kwargs['queue'] is None

        self.b.apply_chord(header_result, body.set(queue='test_queue'))
        called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
        assert called_kwargs['queue'] == 'test_queue'

        @self.app.task(shared=False, queue='test_queue_two')
        def callback_queue(result):
            pass

        self.b.apply_chord(header_result, callback_queue.s())
        called_kwargs = self.app.tasks[unlock].apply_async.call_args[1]
        assert called_kwargs['queue'] == 'test_queue_two'
예제 #42
0
 def setup(self):
     self.b = BaseBackend(
         app=self.app,
         url='sch://*****:*****@hostname.dom'
     )
예제 #43
0
 def test_save_group(self):
     b = BaseBackend(self.app)
     b._save_group = Mock()
     b.save_group('foofoo', 'xxx')
     b._save_group.assert_called_with('foofoo', 'xxx')
예제 #44
0
 def setup(self):
     self.b = BaseBackend(self.app)
예제 #45
0
 def test_forget_interface(self):
     b = BaseBackend()
     with self.assertRaises(NotImplementedError):
         b.forget('foo')