Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
    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
Exemplo n.º 5
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'
Exemplo n.º 6
0
    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
Exemplo n.º 7
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'
Exemplo n.º 8
0
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']
Exemplo n.º 9
0
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']
Exemplo n.º 10
0
    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
Exemplo n.º 11
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.config == config
        assert default_app.config.registry.settings['BROKER_URL'] == 'foo'
Exemplo n.º 12
0
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"]
Exemplo n.º 13
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["CELERY_TIMEZONE"] == "America/Los_Angeles"
Exemplo n.º 14
0
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"]
Exemplo n.º 15
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'
Exemplo n.º 16
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"
Exemplo n.º 17
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'
Exemplo n.º 18
0
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")
Exemplo n.º 19
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'
    assert celery_app.conf['broker_transport_options'] == {
        'visibility_timeout': 18000,
        'max_retries': 5,
    }
Exemplo n.º 20
0
    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'
Exemplo n.º 21
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)
Exemplo n.º 22
0
    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", )
Exemplo n.º 23
0
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')
Exemplo n.º 24
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)