summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-09-10 17:14:59 -0400
committerChris McDonough <chrism@plope.com>2011-09-10 17:14:59 -0400
commitf3b6a3653de8d6c33473d113ab8238eb40695632 (patch)
tree56d0ea369797e158c941e8cfcdbe8edab99afdb2
parentbf00c3ae0f03eb81579a2ce3f1886b2acdc1e462 (diff)
downloadpyramid-f3b6a3653de8d6c33473d113ab8238eb40695632.tar.gz
pyramid-f3b6a3653de8d6c33473d113ab8238eb40695632.tar.bz2
pyramid-f3b6a3653de8d6c33473d113ab8238eb40695632.zip
look up the registry using a threadlocal for bw compatibility in existing (third-party) tests
-rw-r--r--pyramid/config/views.py6
-rw-r--r--pyramid/tests/test_config/test_views.py9
2 files changed, 14 insertions, 1 deletions
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index b179e39b3..703e3cca5 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -34,6 +34,7 @@ from pyramid.httpexceptions import HTTPForbidden
from pyramid.httpexceptions import HTTPNotFound
from pyramid.security import NO_PERMISSION_REQUIRED
from pyramid.static import static_view
+from pyramid.threadlocal import get_current_registry
from pyramid.view import render_view_to_response
from pyramid.config.util import DEFAULT_PHASH
@@ -1411,7 +1412,10 @@ class StaticURLInfo(object):
return reg
def generate(self, path, request, **kw):
- registry = request.registry
+ try:
+ registry = request.registry
+ except AttributeError: # bw compat (for tests)
+ registry = get_current_registry()
for (url, spec, route_name) in self._get_registrations(registry):
if path.startswith(spec):
subpath = path[len(spec):]
diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py
index 5fcad3eec..be5143d45 100644
--- a/pyramid/tests/test_config/test_views.py
+++ b/pyramid/tests/test_config/test_views.py
@@ -3301,6 +3301,15 @@ class TestStaticURLInfo(unittest.TestCase):
result = inst.generate('package:path/abc', request)
self.assertEqual(result, 'http://example.com/foo/abc')
+ def test_generate_registration_no_registry_on_request(self):
+ inst = self._makeOne()
+ registrations = [('http://example.com/foo/', 'package:path/', None)]
+ inst._get_registrations = lambda *x: registrations
+ request = self._makeRequest()
+ del request.registry
+ result = inst.generate('package:path/abc', request)
+ self.assertEqual(result, 'http://example.com/foo/abc')
+
def test_generate_slash_in_name1(self):
inst = self._makeOne()
registrations = [('http://example.com/foo/', 'package:path/', None)]