summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rossi <chris@archimedeanco.com>2014-07-15 18:02:01 -0400
committerChris Rossi <chris@archimedeanco.com>2014-07-15 18:02:01 -0400
commit5350158f666a638293bd2b3d7cd19029e0bab145 (patch)
tree9ec3d2a08b18e6712cdbb9c99de463b720a1e9a9
parentcac23bb790da283fad7ad51ac4c18fc3903ebb92 (diff)
downloadpyramid-5350158f666a638293bd2b3d7cd19029e0bab145.tar.gz
pyramid-5350158f666a638293bd2b3d7cd19029e0bab145.tar.bz2
pyramid-5350158f666a638293bd2b3d7cd19029e0bab145.zip
Test coverage for pyramid.config.views
-rw-r--r--pyramid/config/views.py11
-rw-r--r--pyramid/tests/test_config/test_views.py39
2 files changed, 46 insertions, 4 deletions
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index 4b7bdaa81..00c5622e7 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -1891,6 +1891,12 @@ def isexception(o):
@implementer(IStaticURLInfo)
class StaticURLInfo(object):
+ # Indirection for testing
+ _default_cachebuster = staticmethod(PathSegmentCacheBuster)
+ _default_asset_token_generator = staticmethod(Md5AssetTokenGenerator)
+
+ def _make_default_cachebuster(self):
+ return self._default_cachebuster(self._default_asset_token_generator())
def _get_registrations(self, registry):
try:
@@ -1953,7 +1959,7 @@ class StaticURLInfo(object):
cb = extra.pop('cachebuster', None)
if cb is True:
- cb = DefaultCacheBuster()
+ cb = self._make_default_cachebuster()
if cb:
def cachebuster(subpath, kw):
token = cb.token(spec + subpath)
@@ -2030,6 +2036,3 @@ class StaticURLInfo(object):
config.action(None, callable=register, introspectables=(intr,))
-def DefaultCacheBuster():
- return PathSegmentCacheBuster(Md5AssetTokenGenerator())
-
diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py
index e01aed1f2..0b81f5a6f 100644
--- a/pyramid/tests/test_config/test_views.py
+++ b/pyramid/tests/test_config/test_views.py
@@ -3845,6 +3845,20 @@ class TestStaticURLInfo(unittest.TestCase):
self.assertEqual(result,
'http://example.com/abc%20def#La%20Pe%C3%B1a')
+ def test_generate_url_cachebuster(self):
+ def cachebuster(subpath, kw):
+ kw['foo'] = 'bar'
+ return 'foo' + '/' + subpath, kw
+ inst = self._makeOne()
+ registrations = [(None, 'package:path/', '__viewname', cachebuster)]
+ inst._get_registrations = lambda *x: registrations
+ request = self._makeRequest()
+ def route_url(n, **kw):
+ self.assertEqual(n, '__viewname')
+ self.assertEqual(kw, {'subpath':'foo/abc', 'foo':'bar'})
+ request.route_url = route_url
+ inst.generate('package:path/abc', request)
+
def test_add_already_exists(self):
inst = self._makeOne()
config = self._makeConfig(
@@ -3927,6 +3941,31 @@ class TestStaticURLInfo(unittest.TestCase):
self.assertEqual(config.view_kw['renderer'],
'mypackage:templates/index.pt')
+ def test_add_cachebust_default(self):
+ config = self._makeConfig()
+ inst = self._makeOne()
+ inst._default_asset_token_generator = lambda: lambda pathspec: 'foo'
+ inst.add(config, 'view', 'mypackage:path', cachebuster=True)
+ cachebuster = config.registry._static_url_registrations[0][3]
+ subpath, _ = cachebuster('some/path', None)
+ self.assertEqual(subpath, 'foo/some/path')
+
+ def test_add_cachebust_custom(self):
+ class DummyCacheBuster(object):
+ def token(self, pathspec):
+ return 'foo'
+ def pregenerate(self, token, subpath, kw):
+ kw['x'] = token
+ return subpath, kw
+ config = self._makeConfig()
+ inst = self._makeOne()
+ inst.add(config, 'view', 'mypackage:path',
+ cachebuster=DummyCacheBuster())
+ cachebuster = config.registry._static_url_registrations[0][3]
+ subpath, kw = cachebuster('some/path', {})
+ self.assertEqual(subpath, 'some/path')
+ self.assertEqual(kw['x'], 'foo')
+
class Test_view_description(unittest.TestCase):
def _callFUT(self, view):
from pyramid.config.views import view_description