summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-07-12 13:50:49 +0000
committerChris McDonough <chrism@agendaless.com>2010-07-12 13:50:49 +0000
commit0482bd06bcde5601ea2ab3b01b774e03f92160b7 (patch)
tree5b182307301e402a343977fb44828696dc119d54 /repoze/bfg/tests
parent9336d44d79232b021cc5f871aa43a384958e1920 (diff)
downloadpyramid-0482bd06bcde5601ea2ab3b01b774e03f92160b7.tar.gz
pyramid-0482bd06bcde5601ea2ab3b01b774e03f92160b7.tar.bz2
pyramid-0482bd06bcde5601ea2ab3b01b774e03f92160b7.zip
- New internal exception: ``repoze.bfg.exceptions.URLDecodeError``.
This URL is a subclass of the built-in Python exception named ``UnicodeDecodeError``. - When decoding a URL segment to Unicode fails, the exception raised is now ``repoze.bfg.exceptions.URLDecodeError`` instead of ``UnicodeDecodeError``. This makes it possible to register an exception view invoked specifically when ``repoze.bfg`` cannot decode a URL.
Diffstat (limited to 'repoze/bfg/tests')
-rw-r--r--repoze/bfg/tests/test_traversal.py9
-rw-r--r--repoze/bfg/tests/test_urldispatch.py5
2 files changed, 11 insertions, 3 deletions
diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py
index d21c3ee3e..29f11dd40 100644
--- a/repoze/bfg/tests/test_traversal.py
+++ b/repoze/bfg/tests/test_traversal.py
@@ -43,11 +43,12 @@ class TraversalPathTests(unittest.TestCase):
self.assertEqual(self._callFUT(path), (decoded, decoded))
def test_utf16(self):
+ from repoze.bfg.exceptions import URLDecodeError
import urllib
la = unicode('La Pe\xc3\xb1a', 'utf-8').encode('utf-16')
encoded = urllib.quote(la)
path = '/'.join([encoded, encoded])
- self.assertRaises(TypeError, self._callFUT, path)
+ self.assertRaises(URLDecodeError, self._callFUT, path)
class ModelGraphTraverserTests(unittest.TestCase):
def setUp(self):
@@ -246,7 +247,8 @@ class ModelGraphTraverserTests(unittest.TestCase):
policy = self._makeOne(root)
segment = unicode('LaPe\xc3\xb1a', 'utf-8').encode('utf-16')
environ = self._getEnviron(PATH_INFO='/%s' % segment)
- self.assertRaises(TypeError, policy, environ)
+ from repoze.bfg.exceptions import URLDecodeError
+ self.assertRaises(URLDecodeError, policy, environ)
def test_non_utf8_path_segment_settings_unicode_path_segments_fails(self):
foo = DummyContext()
@@ -254,7 +256,8 @@ class ModelGraphTraverserTests(unittest.TestCase):
policy = self._makeOne(root)
segment = unicode('LaPe\xc3\xb1a', 'utf-8').encode('utf-16')
environ = self._getEnviron(PATH_INFO='/%s' % segment)
- self.assertRaises(TypeError, policy, environ)
+ from repoze.bfg.exceptions import URLDecodeError
+ self.assertRaises(URLDecodeError, policy, environ)
def test_withroute_nothingfancy(self):
model = DummyContext()
diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py
index 69bd3d971..c5fa37758 100644
--- a/repoze/bfg/tests/test_urldispatch.py
+++ b/repoze/bfg/tests/test_urldispatch.py
@@ -224,6 +224,11 @@ class TestCompileRoute(unittest.TestCase):
self.assertEqual(matcher('foo/baz/biz/buz/bar'), None)
self.assertEqual(generator({'baz':1, 'buz':2}), '/foo/1/biz/2/bar')
+ def test_url_decode_error(self):
+ from repoze.bfg.exceptions import URLDecodeError
+ matcher, generator = self._callFUT('/:foo')
+ self.assertRaises(URLDecodeError, matcher, '/%FF%FE%8B%00')
+
class TestCompileRouteMatchFunctional(unittest.TestCase):
def matches(self, pattern, path, result):
from repoze.bfg.urldispatch import _compile_route