From 1db5c4e644296d9627effe1febfea43badf59d40 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 29 Mar 2011 04:22:22 -0400 Subject: branch coverage --- pyramid/tests/test_traversal.py | 52 +++++++++++++++++++++++++++++++++++++++++ pyramid/traversal.py | 8 +++---- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/pyramid/tests/test_traversal.py b/pyramid/tests/test_traversal.py index d0afb9a2b..89edb230b 100644 --- a/pyramid/tests/test_traversal.py +++ b/pyramid/tests/test_traversal.py @@ -336,6 +336,19 @@ class ResourceTreeTraverserTests(unittest.TestCase): self.assertEqual(result['virtual_root'], resource) self.assertEqual(result['virtual_root_path'], ()) + def test_withroute_and_traverse_empty(self): + resource = DummyContext() + traverser = self._makeOne(resource) + environ = {'bfg.routes.matchdict': {'traverse':''}} + result = traverser(environ) + self.assertEqual(result['context'], resource) + self.assertEqual(result['view_name'], '') + self.assertEqual(result['subpath'], ()) + self.assertEqual(result['traversed'], ()) + self.assertEqual(result['root'], resource) + self.assertEqual(result['virtual_root'], resource) + self.assertEqual(result['virtual_root_path'], ()) + class FindInterfaceTests(unittest.TestCase): def _callFUT(self, context, iface): from pyramid.traversal import find_interface @@ -653,6 +666,16 @@ class ResourcePathTupleTests(unittest.TestCase): result = self._callFUT(root) self.assertEqual(result, ('',)) + def test_root_default_emptystring_name(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = '' + other = DummyContext() + other.__parent__ = root + other.__name__ = 'other' + result = self._callFUT(other) + self.assertEqual(result, ('', 'other',)) + def test_nonroot_default(self): root = DummyContext() root.__parent__ = None @@ -802,6 +825,22 @@ class TraversalContextURLTests(unittest.TestCase): result = context_url() self.assertEqual(result, 'http://example.com:5432/') + def test_call_with_virtual_root_path_physical_not_startwith_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' + request = DummyRequest({VH_ROOT_KEY:'/wrong'}) + context_url = self._makeOne(two, request) + result = context_url() + self.assertEqual(result, 'http://example.com:5432/one/two/') + def test_virtual_root_no_virtual_root_path(self): root = DummyContext() root.__name__ = None @@ -1058,6 +1097,19 @@ class TestDefaultRootFactory(unittest.TestCase): self.assertEqual(root.a, 1) self.assertEqual(root.b, 2) +class Test__join_path_tuple(unittest.TestCase): + def _callFUT(self, tup): + from pyramid.traversal import _join_path_tuple + return _join_path_tuple(tup) + + def test_empty_tuple(self): + # tests "or '/'" case + result = self._callFUT(()) + self.assertEqual(result, '/') + + def test_nonempty_tuple(self): + result = self._callFUT(('x',)) + self.assertEqual(result, 'x') def make_traverser(result): class DummyTraverser(object): diff --git a/pyramid/traversal.py b/pyramid/traversal.py index c69892854..540f17a31 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -577,14 +577,14 @@ class ResourceTreeTraverser(object): if 'bfg.routes.matchdict' in environ: matchdict = environ['bfg.routes.matchdict'] - path = matchdict.get('traverse', '/') + path = matchdict.get('traverse', '/') or '/' if hasattr(path, '__iter__'): - # this is a *traverse stararg (not a :traverse) + # this is a *traverse stararg (not a {traverse}) path = '/'.join([quote_path_segment(x) for x in path]) or '/' subpath = matchdict.get('subpath', ()) if not hasattr(subpath, '__iter__'): - # this is not a *subpath stararg (just a :subpath) + # this is not a *subpath stararg (just a {subpath}) subpath = traversal_path(subpath) else: @@ -608,7 +608,7 @@ class ResourceTreeTraverser(object): root = self.root ob = vroot = root - if vpath == '/' or (not vpath): + if vpath == '/': # invariant: vpath must not be empty # prevent a call to traversal_path if we know it's going # to return the empty tuple vpath_tuple = () -- cgit v1.2.3