예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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'
예제 #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
예제 #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'
예제 #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']
예제 #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']
예제 #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
예제 #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'
예제 #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"]
예제 #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"
예제 #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"]
예제 #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'
예제 #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"
예제 #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'
예제 #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")
예제 #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,
    }
예제 #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'
예제 #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)
예제 #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", )
예제 #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')
예제 #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)