look up the registry using a threadlocal for bw compatibility in existing (third-party) tests
| | |
| | | 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 |
| | |
| | | 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):] |
| | |
| | | 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)] |