def test_includeme(self):
        from pyramid_webassets import includeme
        from pyramid_webassets import add_webasset
        from pyramid_webassets import get_webassets_env
        from pyramid_webassets import add_setting
        from pyramid_webassets import get_webassets_env_from_request

        config = Mock()
        add_directive = Mock()
        registerUtility = Mock()
        set_request_property = Mock()

        config.registry = Mock()
        config.registry.registerUtility = registerUtility
        config.add_directive = add_directive
        config.set_request_property = set_request_property

        settings = {"webassets.base_url": "/static", "webassets.base_dir": os.getcwd()}

        config.registry.settings = settings

        includeme(config)

        expected1 = ("add_webasset", add_webasset)
        expected2 = ("get_webassets_env", get_webassets_env)
        expected3 = ("add_webassets_setting", add_setting)

        assert add_directive.call_args_list[0][0] == expected1
        assert add_directive.call_args_list[1][0] == expected2
        assert add_directive.call_args_list[2][0] == expected3

        assert set_request_property.call_args_list[0][0] == (get_webassets_env_from_request, "webassets_env")
 def test_r(self):
     mocks = Mock()
     mocks.Meaning.objects.get_spellings_for.return_value = set(["one"])
     mocks.registry = {mocks.model: ["name"]}
     with patch("babelsearch.reindexer.Meaning", mocks.Meaning):
         with patch("babelsearch.indexer.registry", mocks.registry):
             with patch("babelsearch.reindexer.reindex_model_for_meanings", mocks.rmfm):
                 reindex_for_meanings([0], ["one"])
     self.assertEqual(mocks.rmfm.call_args, ((mocks.model, [0], ["one"]), {"callback": None}))
Example #3
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
Example #4
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_get_webassets_env_from_request(self):
        from pyramid_webassets import get_webassets_env_from_request
        from pyramid_webassets import IWebAssetsEnvironment

        request = Mock()
        request.registry = Mock()
        queryUtility = Mock()
        request.registry.queryUtility = queryUtility

        env = get_webassets_env_from_request(request)
        queryUtility.assert_called_with(IWebAssetsEnvironment)

        assert env != None
    def test_get_webassets_env(self):
        from pyramid_webassets import get_webassets_env
        from pyramid_webassets import IWebAssetsEnvironment

        config = Mock()
        config.registry = Mock()
        queryUtility = Mock()

        config.registry.queryUtility = queryUtility

        env = get_webassets_env(config)
        queryUtility.assert_called_with(IWebAssetsEnvironment)

        assert env != None
    def test_add_web_asset(self):
        from pyramid_webassets import add_webasset

        config = Mock()
        config.registry = Mock()
        queryUtility = Mock()
        env = Mock()
        register = Mock()
        env.register = register
        queryUtility.return_value = env

        config.registry.queryUtility = queryUtility

        add_webasset(config, "foo", "bar")
        register.assert_called_with("foo", "bar")
    def test_add_setting(self):
        from pyramid_webassets import add_setting

        config = Mock()
        config.registry = Mock()
        queryUtility = Mock()
        env = Mock()
        env.config = {}
        register = Mock()
        env.register = register
        queryUtility.return_value = env

        config.registry.queryUtility = queryUtility

        add_setting(config, "foo", "bar")
        assert env.config["foo"] == "bar"
Example #9
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"
Example #10
0
    def test_add_path(self):
        from pyramid_webassets import add_path

        config = Mock()
        config.registry = Mock()
        queryUtility = Mock()
        env = Mock()
        env.config = {}
        register = Mock()
        env.register = register
        queryUtility.return_value = env

        config.registry.queryUtility = queryUtility

        add_path(config, "foo", "/bar")
        env.append_path.assert_called_with("foo", "/bar")
Example #11
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)
Example #12
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)
Example #13
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:://localhost:6379/0"',
            "BROKER_TRANSPORT_OPTIONS": '{"foo": "bar"}',
            "ADMINS": '(("Foo Bar", "foo@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_includeme(self):
        from pyramid_webassets import includeme
        from pyramid_webassets import add_webasset
        from pyramid_webassets import get_webassets_env

        config = Mock()
        add_directive = Mock()
        registerUtility = Mock()

        config.registry = Mock()
        config.registry.registerUtility = registerUtility
        config.add_directive = add_directive

        settings = {"webassets.base_url": "/static", "webassets.base_dir": "/home/sontek"}

        config.registry.settings = settings

        includeme(config)

        expected1 = ("add_webasset", add_webasset)
        expected2 = ("get_webassets_env", get_webassets_env)
        assert add_directive.call_args_list[0][0] == expected1
        assert add_directive.call_args_list[1][0] == expected2