Permalink
Browse files

added support for add_setting

  • Loading branch information...
1 parent f498a8e commit 47100310185a6440e567b5fbbd234cf703197a3f @sontek committed Aug 9, 2012
Showing with 25 additions and 0 deletions.
  1. +4 −0 pyramid_webassets/__init__.py
  2. +21 −0 pyramid_webassets/tests/test_webassets.py
@@ -116,6 +116,9 @@ def get_webassets_env_from_request(request):
""" Get the webassets environment in the registry from the request. """
return request.registry.queryUtility(IWebAssetsEnvironment)
+def add_setting(config, key, value):
+ env = config.registry.queryUtility(IWebAssetsEnvironment)
+ env.config[key] = value
def assets(request, *args, **kwargs):
env = get_webassets_env_from_request(request)
@@ -146,6 +149,7 @@ def includeme(config):
config.add_directive('add_webasset', add_webasset)
config.add_directive('get_webassets_env', get_webassets_env)
+ config.add_directive('add_webassets_setting', add_setting)
config.add_static_view(assets_env.url, assets_env.directory)
config.set_request_property(get_webassets_env_from_request,
'webassets_env', reify=True)
@@ -29,6 +29,23 @@ def test_add_web_asset(self):
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'
+
def test_get_webassets_env(self):
from pyramid_webassets import get_webassets_env
from pyramid_webassets import IWebAssetsEnvironment
@@ -153,6 +170,7 @@ 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()
@@ -176,8 +194,11 @@ def test_includeme(self):
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')

0 comments on commit 4710031

Please sign in to comment.