Chris McDonough
2012-02-18 118ea0c512a82d3dfcc6fe283afcd30818c14993
deprecate pyramid.interfaces.IContextURL and pyramid.traversal.TraversalContextURL, add tests for ResourceURL constructor logic
4 files modified
90 ■■■■ changed files
pyramid/interfaces.py 11 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_traversal.py 64 ●●●● patch | view | raw | blame | history
pyramid/tests/test_url.py 3 ●●●● patch | view | raw | blame | history
pyramid/traversal.py 12 ●●●●● patch | view | raw | blame | history
pyramid/interfaces.py
@@ -1,3 +1,5 @@
from zope.deprecation import deprecated
from zope.interface import (
    Attribute,
    Interface,
@@ -780,6 +782,15 @@
    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 """
pyramid/tests/test_traversal.py
@@ -1,6 +1,8 @@
import unittest
import warnings
from pyramid.testing import cleanUp
from pyramid.compat import (
    text_,
    native_,
@@ -8,6 +10,11 @@
    url_quote,
    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):
@@ -452,9 +459,8 @@
        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 @@
            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 @@
        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 @@
    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 @@
        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 @@
        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),
pyramid/tests/test_url.py
@@ -27,7 +27,8 @@
        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):
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 @@
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 '/'