def test_adds_when_initialized(self): 'if router is passed a celery task when initialized it wraps with it' r = CeleryRouter(celery_task=self.celery.task) l = lambda x: x l.__name__ = 'test' r.node(['test'])(l) self.assertTrue(isinstance(r.functions[prefix('test')], Task))
class CeleryRouterTests(TestCase): 'tests for using celery to route nodes' def setUp(self): self.celery = self.get_test_celery() self.router = CeleryRouter(self.celery.task) def get_test_celery(self): celery = Celery() celery.conf.update( CELERY_ALWAYS_EAGER=True ) return celery def test_registers_as_task(self): 'registers the function as a task' l = lambda x: x l.__name__ = 'test' self.router.node(['test'], celery_task=self.celery.task)(l) self.assertTrue( isinstance(self.router.functions[prefix('test')], Task) ) def test_adds_when_initialized(self): 'if router is passed a celery task when initialized it wraps with it' r = CeleryRouter(celery_task=self.celery.task) l = lambda x: x l.__name__ = 'test' r.node(['test'])(l) self.assertTrue( isinstance(r.functions[prefix('test')], Task) ) def test_calls_delay(self): 'calls delay to route' func = lambda n: n func.name = 'name' self.router.node(tuple(), entry_point=True)(func) node = mock.Mock() # replace node with mock to test call self.router.functions['name'] = node self.router(x=1) node.delay.assert_called_with(_origin='__entry_point', x=1) def test_get_name_celery(self): 'gets the name of a celery-decorated function' l = lambda x: x l.__name__ = 'test' l = self.celery.task(l) self.assertEqual(prefix('test'), self.router.get_name(l))
def test_adds_when_initialized(self): 'if router is passed a celery task when initialized it wraps with it' r = CeleryRouter(celery_task=self.celery.task) l = lambda x: x l.__name__ = 'test' r.node(['test'])(l) self.assertTrue( isinstance(r.functions[prefix('test')], Task) )
class CeleryRouterTests(TestCase): 'tests for using celery to route nodes' def setUp(self): self.celery = self.get_test_celery() self.router = CeleryRouter(self.celery.task) def get_test_celery(self): celery = Celery() celery.conf.update(CELERY_ALWAYS_EAGER=True) return celery def test_registers_as_task(self): 'registers the function as a task' l = lambda x: x l.__name__ = 'test' self.router.node(['test'], celery_task=self.celery.task)(l) self.assertTrue(isinstance(self.router.functions[prefix('test')], Task)) def test_adds_when_initialized(self): 'if router is passed a celery task when initialized it wraps with it' r = CeleryRouter(celery_task=self.celery.task) l = lambda x: x l.__name__ = 'test' r.node(['test'])(l) self.assertTrue(isinstance(r.functions[prefix('test')], Task)) def test_calls_delay(self): 'calls delay to route' func = lambda n: n func.name = 'name' self.router.node(tuple(), entry_point=True)(func) node = mock.Mock() # replace node with mock to test call self.router.functions['name'] = node self.router(x=1) node.delay.assert_called_with(_origin='__entry_point', x=1) def test_get_name_celery(self): 'gets the name of a celery-decorated function' l = lambda x: x l.__name__ = 'test' l = self.celery.task(l) self.assertEqual(prefix('test'), self.router.get_name(l))
def setUp(self): self.celery = self.get_test_celery() self.router = CeleryRouter(self.celery.task)
'simple celery app' from celery import Celery from emit.router.celery import CeleryRouter import logging app = Celery('celery_emit_example', broker='redis://') app.conf.update(CELERY_IMPORTS=('tasks', )) router = CeleryRouter(celery_task=app.task, node_modules=['tasks']) logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)