diff options
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_traversal.py | 55 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_url.py | 2 |
2 files changed, 56 insertions, 1 deletions
diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 1486e5b91..ebac680d4 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -412,6 +412,46 @@ class ModelPathTests(unittest.TestCase): baz.__parent__ = bar baz.__name__ = 'baz' result = self._callFUT(baz, 'this/theotherthing', 'that') + self.assertEqual(result, '/foo%20/bar/baz/this%2Ftheotherthing/that') + + def test_root_default(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = None + request = DummyRequest() + result = self._callFUT(root) + self.assertEqual(result, '/') + + def test_nonroot_default(self): + root = DummyContext() + root.__parent__ = None + root.__name__ = None + other = DummyContext() + other.__parent__ = root + other.__name__ = 'other' + request = DummyRequest() + result = self._callFUT(other) + self.assertEqual(result, '/other') + +class ModelPathTupleTests(unittest.TestCase): + def _callFUT(self, model, *elements): + from repoze.bfg.traversal import model_path_tuple + return model_path_tuple(model, *elements) + + def test_it(self): + baz = DummyContext() + bar = DummyContext(baz) + foo = DummyContext(bar) + root = DummyContext(foo) + root.__parent__ = None + root.__name__ = None + foo.__parent__ = root + foo.__name__ = 'foo ' + bar.__parent__ = foo + bar.__name__ = 'bar' + baz.__parent__ = bar + baz.__name__ = 'baz' + result = self._callFUT(baz, 'this/theotherthing', 'that') self.assertEqual(result, ('','foo ', 'bar', 'baz', 'this/theotherthing', 'that')) @@ -434,6 +474,21 @@ class ModelPathTests(unittest.TestCase): result = self._callFUT(other) self.assertEqual(result, ('', 'other')) +class QuotePathSegmentTests(unittest.TestCase): + def _callFUT(self, s): + from repoze.bfg.traversal import quote_path_segment + return quote_path_segment(s) + + def test_unicode(self): + la = unicode('/La Pe\xc3\xb1a', 'utf-8') + result = self._callFUT(la) + self.assertEqual(result, '%2FLa%20Pe%C3%B1a') + + def test_string(self): + s = '/ hello!' + result = self._callFUT(s) + self.assertEqual(result, '%2F%20hello%21') + class TraversalContextURLTests(unittest.TestCase): def _makeOne(self, context, url): return self._getTargetClass()(context, url) diff --git a/repoze/bfg/tests/test_url.py b/repoze/bfg/tests/test_url.py index dee86c05f..b9733f802 100644 --- a/repoze/bfg/tests/test_url.py +++ b/repoze/bfg/tests/test_url.py @@ -40,7 +40,7 @@ class ModelURLTests(unittest.TestCase): result = self._callFUT(context, request, 'this/theotherthing', 'that') self.assertEqual( result, - 'http://example.com/context/this/theotherthing/that') + 'http://example.com/context/this%2Ftheotherthing/that') def test_unicode_in_element_names(self): self._registerContextURL() |
