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
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 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': '/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 assert set_request_property.call_args_list[0][0] == \ (get_webassets_env_from_request, 'webassets_env')
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_destination_package(): """Testing translation package:path resolve.""" request = Mock() request.registry = {'config': Mock()} mock_configuration = {'localize.translation.destination': 'tests:translations'} request.registry['config'].configure_mock(**mock_configuration) result = destination_path(request) assert result == os.path.join(package_path(sys.modules['tests']), 'translations')
def test_destination_filename(): """Testing translation fullpath resolve.""" request = Mock() request.registry = {'config': Mock()} path = '/some/path/to/translations' mock_configuration = {'localize.translation.destination': path} request.registry['config'].configure_mock(**mock_configuration) result = destination_path(request) assert result == path
def test_destination_filename(): """Testing translation fullpath resolve.""" request = Mock() path = "/some/path/to/translations" request.registry = { "localize": build_localize_config({"localize.translation.destination": path}) } result = destination_path(request) assert result == path
def test_destination_filename(): """Testing translation fullpath resolve.""" request = Mock() request.registry = {'config': Mock()} path = '/some/path/to/translations' mock_configuration = { 'localize.translation.destination': path} request.registry['config'].configure_mock(**mock_configuration) result = destination_path(request) assert result == path
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_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}) )
def test_destination_package(): """Testing translation package:path resolve.""" request = Mock() request.registry = { "localize": build_localize_config( {"localize.translation.destination": "tests:translations"}) } result = destination_path(request) assert result == os.path.join(package_path(sys.modules["tests"]), "translations")
def test_destination_package(): """Testing translation package:path resolve.""" request = Mock() request.registry = {'config': Mock()} mock_configuration = { 'localize.translation.destination': 'tests:translations' } request.registry['config'].configure_mock(**mock_configuration) result = destination_path(request) assert result == os.path.join(package_path(sys.modules['tests']), 'translations')
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_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 is not None
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_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 is not 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_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_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')
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'
def locale_negotiator_request(): """Request for locale_negotiator tests.""" request = Mock() mock_configuration = { 'cookies': {'_LOCALE_': 'cz'}, '_LOCALE_': 'fr', 'accept_language.best_match.return_value': 'de', 'path': '/pl/page'} request.configure_mock(**mock_configuration) config = Mock() config.configure_mock(**{ 'localize.locales.available': ['en', 'pl', 'de', 'cz', 'fr'], 'localize.locales.default': 'en' }) request.registry = {'config': config} return request
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 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 locale_negotiator_request(): """Request for locale_negotiator tests.""" request = Mock() mock_configuration = { 'cookies': { '_LOCALE_': 'cz' }, '_LOCALE_': 'fr', 'accept_language.best_match.return_value': 'de', 'path': '/pl/page' } request.configure_mock(**mock_configuration) config = Mock() config.configure_mock( **{ 'localize.locales.available': ['en', 'pl', 'de', 'cz', 'fr'], 'localize.locales.default': 'en' }) request.registry = {'config': config} return request
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() add_request_method = Mock() config.registry = Mock() config.registry.registerUtility = registerUtility config.add_directive = add_directive config.add_request_method = add_request_method 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 add_request_method.call_args_list[0][0] == \ (get_webassets_env_from_request, 'webassets_env')
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')