diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-06-26 03:39:27 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-06-26 03:39:27 +0000 |
| commit | 25cbe149246aba58b5eba4c13dc67260f09d3862 (patch) | |
| tree | e1d3dcc01ef3847d7a39a7c04de8d65da77ab386 /repoze/bfg/tests | |
| parent | 1e40cf21f1bb41feee5f377db8b02a06657d2001 (diff) | |
| download | pyramid-25cbe149246aba58b5eba4c13dc67260f09d3862.tar.gz pyramid-25cbe149246aba58b5eba4c13dc67260f09d3862.tar.bz2 pyramid-25cbe149246aba58b5eba4c13dc67260f09d3862.zip | |
- Cause ``:segment`` matches in route paths to put a Unicode-decoded
and URL-dequoted value in the matchdict for the value matched.
Previously a non-decoded non-URL-dequoted string was placed in the
matchdict as the value.
- Cause ``*remainder`` matches in route paths to put a *tuple* in the
matchdict dictionary in order to be able to present Unicode-decoded
and URL-dequoted values for the traversal path. Previously a
non-decoded non-URL-dequoted string was placed in the matchdict as
the value.
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_traversal.py | 30 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_urldispatch.py | 19 |
2 files changed, 40 insertions, 9 deletions
diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 68b920fa4..4a4080aab 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -270,7 +270,7 @@ class ModelGraphTraverserTests(unittest.TestCase): self.assertEqual(result['virtual_root'], model) self.assertEqual(result['virtual_root_path'], ()) - def test_withroute_with_subpath(self): + def test_withroute_with_subpath_string(self): model = DummyContext() traverser = self._makeOne(model) environ = {'bfg.routes.matchdict': {'subpath':'/a/b/c'}} @@ -283,7 +283,20 @@ class ModelGraphTraverserTests(unittest.TestCase): self.assertEqual(result['virtual_root'], model) self.assertEqual(result['virtual_root_path'], ()) - def test_withroute_and_traverse(self): + def test_withroute_with_subpath_tuple(self): + model = DummyContext() + traverser = self._makeOne(model) + environ = {'bfg.routes.matchdict': {'subpath':('a', 'b', 'c')}} + result = traverser(environ) + self.assertEqual(result['context'], model) + self.assertEqual(result['view_name'], '') + self.assertEqual(result['subpath'], ('a', 'b','c')) + self.assertEqual(result['traversed'], ()) + self.assertEqual(result['root'], model) + self.assertEqual(result['virtual_root'], model) + self.assertEqual(result['virtual_root_path'], ()) + + def test_withroute_and_traverse_string(self): model = DummyContext() traverser = self._makeOne(model) environ = {'bfg.routes.matchdict': {'traverse':'foo/bar'}} @@ -296,6 +309,19 @@ class ModelGraphTraverserTests(unittest.TestCase): self.assertEqual(result['virtual_root'], model) self.assertEqual(result['virtual_root_path'], ()) + def test_withroute_and_traverse_tuple(self): + model = DummyContext() + traverser = self._makeOne(model) + environ = {'bfg.routes.matchdict': {'traverse':('foo', 'bar')}} + result = traverser(environ) + self.assertEqual(result['context'], model) + self.assertEqual(result['view_name'], 'foo') + self.assertEqual(result['subpath'], ('bar',)) + self.assertEqual(result['traversed'], ()) + self.assertEqual(result['root'], model) + self.assertEqual(result['virtual_root'], model) + self.assertEqual(result['virtual_root_path'], ()) + class FindInterfaceTests(unittest.TestCase): def _callFUT(self, context, iface): from repoze.bfg.traversal import find_interface diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py index 014401008..0bee548c5 100644 --- a/repoze/bfg/tests/test_urldispatch.py +++ b/repoze/bfg/tests/test_urldispatch.py @@ -132,10 +132,10 @@ class TestCompileRoute(unittest.TestCase): def test_with_star(self): matcher, generator = self._callFUT('/foo/:baz/biz/:buz/bar*traverse') self.assertEqual(matcher('/foo/baz/biz/buz/bar'), - {'baz':'baz', 'buz':'buz', 'traverse':''}) + {'baz':'baz', 'buz':'buz', 'traverse':()}) self.assertEqual(matcher('/foo/baz/biz/buz/bar/everything/else/here'), {'baz':'baz', 'buz':'buz', - 'traverse':'/everything/else/here'}) + 'traverse':('everything', 'else', 'here')}) self.assertEqual(matcher('foo/baz/biz/buz/bar'), None) self.assertEqual(generator( {'baz':1, 'buz':2, 'traverse':u'/a/b'}), '/foo/1/biz/2/bar/a/b') @@ -167,9 +167,14 @@ class TestCompileRouteMatchFunctional(unittest.TestCase): self.matches('/:x', '/', {'x':''}) self.matches('/:x', '/a', {'x':'a'}) self.matches('zzz/:x', '/zzz/abc', {'x':'abc'}) - self.matches('zzz/:x*traverse', '/zzz/abc', {'x':'abc', 'traverse':''}) - self.matches('zzz/:x*traverse', '/zzz/abc/def/g', {'x':'abc', - 'traverse':'/def/g'}) + self.matches('zzz/:x*traverse', '/zzz/abc', {'x':'abc', 'traverse':()}) + self.matches('zzz/:x*traverse', '/zzz/abc/def/g', + {'x':'abc', 'traverse':('def', 'g')}) + self.matches('*traverse', '/zzz/abc', {'traverse':('zzz', 'abc')}) + self.matches('*traverse', '/zzz/%20abc', {'traverse':('zzz', ' abc')}) + self.matches(':x', '/La%20Pe%C3%B1a', {'x':u'La Pe\xf1a'}) + self.matches('*traverse', '/La%20Pe%C3%B1a/x', + {'traverse':(u'La Pe\xf1a', 'x')}) def test_generator_functional(self): self.generates('', {}, '/') @@ -186,8 +191,8 @@ class TestCompileRouteMatchFunctional(unittest.TestCase): self.generates('/:x*y', {'x':unicode('/La Pe\xc3\xb1a', 'utf-8'), 'y':'/rest/of/path'}, '/%2FLa%20Pe%C3%B1a/rest/of/path') - - + self.generates('*traverse', {'traverse':('a', u'La Pe\xf1a')}, + '/a/La%20Pe%C3%B1a') class DummyRootFactory(object): def __init__(self, result): |
