diff options
| author | Chris McDonough <chrism@plope.com> | 2012-02-18 15:18:36 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-02-18 15:18:36 -0500 |
| commit | 118ea0c512a82d3dfcc6fe283afcd30818c14993 (patch) | |
| tree | d5086e3b3a33799d10533325f76f06736c7e537a | |
| parent | e75229aede80ade185d0624f6e1cc05e4db23513 (diff) | |
| download | pyramid-118ea0c512a82d3dfcc6fe283afcd30818c14993.tar.gz pyramid-118ea0c512a82d3dfcc6fe283afcd30818c14993.tar.bz2 pyramid-118ea0c512a82d3dfcc6fe283afcd30818c14993.zip | |
deprecate pyramid.interfaces.IContextURL and pyramid.traversal.TraversalContextURL, add tests for ResourceURL constructor logic
| -rw-r--r-- | pyramid/interfaces.py | 11 | ||||
| -rw-r--r-- | pyramid/tests/test_traversal.py | 64 | ||||
| -rw-r--r-- | pyramid/tests/test_url.py | 3 | ||||
| -rw-r--r-- | pyramid/traversal.py | 12 |
4 files changed, 78 insertions, 12 deletions
diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py index 5b9edf31a..399b3efa3 100644 --- a/pyramid/interfaces.py +++ b/pyramid/interfaces.py @@ -1,3 +1,5 @@ +from zope.deprecation import deprecated + from zope.interface import ( Attribute, Interface, @@ -780,6 +782,15 @@ class IContextURL(IResourceURL): def __call__(): """ Return a URL that points to the context. """ +deprecated( + 'IContextURL', + 'As of Pyramid 1.3 the, "pyramid.interfaces.IContextURL" interface is ' + 'scheduled to be removed. Use the ' + '"pyramid.config.Configurator.add_resource_url_adapter" method to register' + 'a class that implements "pyramid.interfaces.IResourceURL" instead.' + 'See the "What\'s new In Pyramid 1.3" document for a further description.' + ) + class IPackageOverrides(Interface): """ Utility for pkg_resources overrides """ diff --git a/pyramid/tests/test_traversal.py b/pyramid/tests/test_traversal.py index 1f9971ca5..8261ad7d9 100644 --- a/pyramid/tests/test_traversal.py +++ b/pyramid/tests/test_traversal.py @@ -1,6 +1,8 @@ import unittest +import warnings from pyramid.testing import cleanUp + from pyramid.compat import ( text_, native_, @@ -9,6 +11,11 @@ from pyramid.compat import ( PY3, ) +with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always') + from pyramid.interfaces import IContextURL + assert(len(w) == 1) + class TraversalPathTests(unittest.TestCase): def _callFUT(self, path): from pyramid.traversal import traversal_path @@ -452,9 +459,8 @@ class ResourceTreeTraverserTests(unittest.TestCase): self.assertEqual(result['virtual_root_path'], ()) def test_call_with_environ(self): - import warnings - warnings.filterwarnings('ignore') - try: + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings('always') policy = self._makeOne(None) environ = self._getEnviron() result = policy(environ) @@ -465,8 +471,7 @@ class ResourceTreeTraverserTests(unittest.TestCase): self.assertEqual(result['root'], policy.root) self.assertEqual(result['virtual_root'], policy.root) self.assertEqual(result['virtual_root_path'], ()) - finally: - warnings.resetwarnings() + self.assertEqual(len(w), 1) class FindInterfaceTests(unittest.TestCase): def _callFUT(self, context, iface): @@ -857,13 +862,13 @@ class QuotePathSegmentTests(unittest.TestCase): result = self._callFUT(s) self.assertEqual(result, 'abc') -class TraversalContextURLTests(unittest.TestCase): +class ResourceURLTests(unittest.TestCase): def _makeOne(self, context, url): return self._getTargetClass()(context, url) def _getTargetClass(self): - from pyramid.traversal import TraversalContextURL - return TraversalContextURL + from pyramid.traversal import ResourceURL + return ResourceURL def _registerTraverser(self, traverser): from pyramid.threadlocal import get_current_registry @@ -874,16 +879,21 @@ class TraversalContextURLTests(unittest.TestCase): def test_class_conforms_to_IContextURL(self): from zope.interface.verify import verifyClass - from pyramid.interfaces import IContextURL verifyClass(IContextURL, self._getTargetClass()) def test_instance_conforms_to_IContextURL(self): from zope.interface.verify import verifyObject - from pyramid.interfaces import IContextURL context = DummyContext() request = DummyRequest() verifyObject(IContextURL, self._makeOne(context, request)) + def test_instance_conforms_to_IResourceURL(self): + from pyramid.interfaces import IResourceURL + from zope.interface.verify import verifyObject + context = DummyContext() + request = DummyRequest() + verifyObject(IResourceURL, self._makeOne(context, request)) + def test_call_withlineage(self): baz = DummyContext() bar = DummyContext(baz) @@ -1036,6 +1046,39 @@ class TraversalContextURLTests(unittest.TestCase): result = context_url() self.assertEqual(result, 'abc') + def test_IResourceURL_attributes_with_vroot(self): + from pyramid.interfaces import VH_ROOT_KEY + root = DummyContext() + root.__parent__ = None + root.__name__ = None + one = DummyContext() + one.__parent__ = root + one.__name__ = 'one' + two = DummyContext() + two.__parent__ = one + two.__name__ = 'two' + environ = {VH_ROOT_KEY:'/one'} + request = DummyRequest(environ) + context_url = self._makeOne(two, request) + self.assertEqual(context_url.physical_path, '/one/two/') + self.assertEqual(context_url.virtual_path, '/two/') + + def test_IResourceURL_attributes_no_vroot(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = None + one = DummyContext() + one.__parent__ = root + one.__name__ = 'one' + two = DummyContext() + two.__parent__ = one + two.__name__ = 'two' + environ = {} + request = DummyRequest(environ) + context_url = self._makeOne(two, request) + self.assertEqual(context_url.physical_path, '/one/two/') + self.assertEqual(context_url.virtual_path, '/one/two/') + class TestVirtualRoot(unittest.TestCase): def setUp(self): cleanUp() @@ -1048,7 +1091,6 @@ class TestVirtualRoot(unittest.TestCase): return virtual_root(resource, request) def test_registered(self): - from pyramid.interfaces import IContextURL from zope.interface import Interface request = _makeRequest() request.registry.registerAdapter(DummyContextURL, (Interface,Interface), diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py index 3c36363ed..7b05368ce 100644 --- a/pyramid/tests/test_url.py +++ b/pyramid/tests/test_url.py @@ -27,7 +27,8 @@ class TestURLMethodsMixin(unittest.TestCase): return request def _registerContextURL(self, reg): - from pyramid.interfaces import IContextURL + with warnings.catch_warnings(record=True): + from pyramid.interfaces import IContextURL from zope.interface import Interface class DummyContextURL(object): def __init__(self, context, request): diff --git a/pyramid/traversal.py b/pyramid/traversal.py index 9801f8f18..328fde4a5 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -1,5 +1,7 @@ import warnings +from zope.deprecation import deprecated + from zope.interface import implementer from zope.interface.interfaces import IInterface @@ -796,6 +798,16 @@ class ResourceURL(object): TraversalContextURL = ResourceURL # bw compat as of 1.3 +deprecated( + 'TraversalContextURL', + 'As of Pyramid 1.3 the, "pyramid.traversal.TraversalContextURL" class is ' + 'scheduled to be removed. Use the ' + '"pyramid.config.Configurator.add_resource_url_adapter" method to register' + 'a class that implements "pyramid.interfaces.IResourceURL" instead.' + 'See the "What\'s new In Pyramid 1.3" document for a further description.' + ) + + @lru_cache(1000) def _join_path_tuple(tuple): return tuple and '/'.join([quote_path_segment(x) for x in tuple]) or '/' |
