def test_result_backend(self): from pyramid_celery import includeme from celery.app import default_app from celery.backends.redis import RedisBackend from celery.backends.amqp import AMQPBackend config = Mock() config.registry = Mock() settings = { 'CELERY_RESULT_BACKEND': '"amqp"' } config.registry.settings = settings includeme(config) self.assertIsInstance(default_app.backend, AMQPBackend) settings = { 'CELERY_RESULT_BACKEND': '"redis"' } config.registry.settings = settings includeme(config) self.assertIsInstance(default_app.backend, RedisBackend)
def test_includeme_default(): from pyramid_celery import includeme from pyramid_celery import celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) assert celery_app.conf['BROKER_URL'] is None
def test_includeme(self): from pyramid_celery import includeme from celery.app import default_app config = Mock() config.registry = Mock() settings = {'CELERY_ALWAYS_EAGER': True} config.registry.settings = settings includeme(config) assert default_app.config == config
def test_includeme_custom_config(): from pyramid_celery import includeme from pyramid_celery import celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery('tests/configs/dev.ini') assert celery_app.conf['BROKER_URL'] == 'redis://localhost:1337/0'
def test_includeme_custom_config(): from pyramid_celery import includeme from pyramid_celery import celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery('tests/configs/dev.ini') assert celery_app.conf['broker_url'] == 'redis://localhost:1337/0' assert celery_app.conf['timezone'] == 'America/Los_Angeles'
def test_celery_accept_content(): from pyramid_celery import includeme, celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery('tests/configs/dev.ini') assert celery_app.conf['CELERY_ACCEPT_CONTENT'] == ['json', 'xml']
def test_celery_imports(): from pyramid_celery import includeme, celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery('tests/configs/imports.ini') assert celery_app.conf['imports'] == ['myapp.tasks', 'otherapp.tasks']
def test_includeme(self): from pyramid_celery import includeme from pyramid_celery import celery from pyramid_celery import Task config = Mock() config.registry = Mock() settings = {"CELERY_ALWAYS_EAGER": True} config.registry.settings = settings includeme(config) assert celery.config == config assert Task.app.config == config
def test_includeme_with_quoted_string(self): from pyramid_celery import includeme from celery.app import default_app config = Mock() config.registry = Mock() settings = {'CELERY_ALWAYS_EAGER': True, 'BROKER_URL': '"foo"'} config.registry.settings = settings includeme(config) assert default_app.config == config assert default_app.config.registry.settings['BROKER_URL'] == 'foo'
def test_celery_imports(): from pyramid_celery import includeme, celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery("tests/configs/imports.ini") assert celery_app.conf["CELERY_IMPORTS"] == ["myapp.tasks", "otherapp.tasks"]
def test_includeme_custom_config(): from pyramid_celery import includeme from pyramid_celery import celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery("tests/configs/dev.ini") assert celery_app.conf["BROKER_URL"] == "redis://localhost:1337/0" assert celery_app.conf["CELERY_TIMEZONE"] == "America/Los_Angeles"
def test_celery_accept_content(): from pyramid_celery import includeme, celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery("tests/configs/dev.ini") assert celery_app.conf["CELERY_ACCEPT_CONTENT"] == ["json", "xml"]
def test_includeme_use_celeryconfig(): from pyramid_celery import includeme from pyramid_celery import celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery('tests/configs/useceleryconfig.ini') assert celery_app.conf['broker_url'] == 'redis://localhost:1337/0'
def test_includeme_use_celeryconfig(): from pyramid_celery import includeme from pyramid_celery import celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery("tests/configs/useceleryconfig.ini") assert celery_app.conf["BROKER_URL"] == "redis://localhost:1337/0"
def test_includeme_with_quoted_string(self): from pyramid_celery import includeme from celery.app import default_app config = Mock() config.registry = Mock() settings = { 'CELERY_ALWAYS_EAGER': True, 'BROKER_URL': '"foo"' } config.registry.settings = settings includeme(config) assert default_app.conf['BROKER_URL'] == 'foo'
def test_ini_logging(): from celery import signals from pyramid_celery import includeme from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery("tests/configs/dev.ini") with mock.patch("pyramid_celery.setup_logging") as setup_logging: signals.setup_logging.send(sender=None, loglevel="INFO", logfile=None, format="", colorize=False) assert setup_logging.called_with("tests/configs/dev.ini")
def test_includeme_custom_config(): from pyramid_celery import includeme from pyramid_celery import celery_app from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery('tests/configs/dev.ini') assert celery_app.conf['broker_url'] == 'redis://localhost:1337/0' assert celery_app.conf['timezone'] == 'America/Los_Angeles' assert celery_app.conf['broker_transport_options'] == { 'visibility_timeout': 18000, 'max_retries': 5, }
def test_celery_quoted_values(self): from pyramid_celery import includeme from celery.app import default_app settings = { 'BROKER_URL': '"redis://localhost:6379/0"', 'BROKER_TRANSPORT_OPTIONS': '{"foo": "bar"}', } config = Mock() config.registry = Mock() config.registry.settings = settings includeme(config) new_settings = default_app.conf assert new_settings['BROKER_URL'] == 'redis://localhost:6379/0'
def setUp(self): settings = {'mako.directories': 'mosileno:templates'} self.config = testing.setUp(settings=settings) self.config.add_static_view('static', 'mosileno:static') from sqlalchemy import create_engine engine = create_engine('sqlite://') DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: alfred = User("alfred", "alfredo", workfactor=1) DBSession.add(alfred) self.config.testing_securitypolicy(userid='alfred', permissive=False) celery_settings = {'CELERY_ALWAYS_EAGER': True, 'CELERY_EAGER_PROPAGATES_EXCEPTIONS': True, } celery_config = Mock() celery_config.registry = Mock() celery_config.registry.settings = celery_settings pyramid_celery.includeme(celery_config)
def test_detailed_includeme(self): from pyramid_celery import includeme from celery.app import default_app settings = { 'CELERY_ALWAYS_EAGER': 'true', 'CELERYD_CONCURRENCY': '1', 'BROKER_URL': '"redis:://*****:*****@bar"), ("Baz Qux", "baz@qux"))', 'CELERYD_TASK_TIME_LIMIT': '0.1', 'CASSANDRA_SERVERS': '["foo", "bar"]', 'CELERY_ANNOTATIONS': '[1, 2, 3]', # any 'CELERY_ROUTERS': 'some.string', # also any 'SOME_KEY': 'SOME VALUE', 'CELERY_IMPORTS': '("myapp.tasks", )' } config = Mock() config.registry = Mock() config.registry.settings = settings includeme(config) new_settings = default_app.conf # Check conversions assert new_settings['CELERY_ALWAYS_EAGER'] == True assert new_settings['CELERYD_CONCURRENCY'] == 1 assert new_settings['ADMINS'] == ( ("Foo Bar", "foo@bar"), ("Baz Qux", "baz@qux") ) assert new_settings['BROKER_TRANSPORT_OPTIONS'] == {"foo": "bar"} assert new_settings['CELERYD_TASK_TIME_LIMIT'] > 0.09 assert new_settings['CELERYD_TASK_TIME_LIMIT'] < 0.11 assert new_settings['CASSANDRA_SERVERS'] == ["foo", "bar"] assert new_settings['CELERY_ANNOTATIONS'] == [1, 2, 3] assert new_settings['CELERY_ROUTERS'] == 'some.string' assert new_settings['SOME_KEY'] == settings['SOME_KEY'] assert new_settings['CELERY_IMPORTS'] == ("myapp.tasks", )
def test_ini_logging(): from celery import signals from pyramid_celery import includeme from pyramid import testing from pyramid.registry import Registry config = testing.setUp() config.registry = Registry() config.registry.settings = {} includeme(config) config.configure_celery('tests/configs/dev.ini') with mock.patch('pyramid_celery.setup_logging') as setup_logging: signals.setup_logging.send( sender=None, loglevel='INFO', logfile=None, format='', colorize=False, ) setup_logging.assert_called_with('tests/configs/dev.ini')
def setUp(self): settings = {'mako.directories': 'mosileno:templates'} self.config = testing.setUp(settings=settings) self.config.add_static_view('static', 'mosileno:static') from sqlalchemy import create_engine engine = create_engine('sqlite://') DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: alfred = User("alfred", "alfredo", workfactor=1) DBSession.add(alfred) self.config.testing_securitypolicy(userid='alfred', permissive=False) celery_settings = { 'CELERY_ALWAYS_EAGER': True, 'CELERY_EAGER_PROPAGATES_EXCEPTIONS': True, } celery_config = Mock() celery_config.registry = Mock() celery_config.registry.settings = celery_settings pyramid_celery.includeme(celery_config)