diff options
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_registry.py | 18 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_traversal.py | 39 |
2 files changed, 57 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_registry.py b/repoze/bfg/tests/test_registry.py index 0b7eda586..f10fe6a52 100644 --- a/repoze/bfg/tests/test_registry.py +++ b/repoze/bfg/tests/test_registry.py @@ -117,6 +117,22 @@ class TestGetOptions(unittest.TestCase): self.assertEqual(result['debug_notfound'], True) self.assertEqual(result['debug_authorization'], True) + def test_unicode_path_segments(self): + get_options = self._getFUT() + result = get_options({}) + self.assertEqual(result['unicode_path_segments'], False) + result = get_options({'unicode_path_segments':'false'}) + self.assertEqual(result['unicode_path_segments'], False) + result = get_options({'unicode_path_segments':'t'}) + self.assertEqual(result['unicode_path_segments'], True) + result = get_options({'unicode_path_segments':'1'}) + self.assertEqual(result['unicode_path_segments'], True) + result = get_options({}, {'BFG_UNICODE_PATH_SEGMENTS':'1'}) + self.assertEqual(result['unicode_path_segments'], True) + result = get_options({'unicode_path_segments':'false'}, + {'BFG_UNICODE_PATH_SEGMENTS':'1'}) + self.assertEqual(result['unicode_path_segments'], True) + class TestSettings(unittest.TestCase): def _getTargetClass(self): from repoze.bfg.registry import Settings @@ -131,12 +147,14 @@ class TestSettings(unittest.TestCase): self.assertEqual(settings.reload_templates, False) self.assertEqual(settings.debug_notfound, False) self.assertEqual(settings.debug_authorization, False) + self.assertEqual(settings.unicode_path_segments, True) def test_with_option(self): settings = self._makeOne(reload_templates=True) self.assertEqual(settings.reload_templates, True) self.assertEqual(settings.debug_notfound, False) self.assertEqual(settings.debug_authorization, False) + self.assertEqual(settings.unicode_path_segments, True) class TestThreadLocalRegistryManager(unittest.TestCase, PlacelessSetup): def setUp(self): diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 32be1ebbb..21e2b6180 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -162,6 +162,42 @@ class ModelGraphTraverserTests(unittest.TestCase, PlacelessSetup): self.assertEqual(ctx.__parent__, bar) self.failIf(isProxy(ctx.__parent__)) + def test_non_utf8_path_segment_unicode_path_segments_fails(self): + foo = DummyContext() + root = DummyContext(foo) + 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) + + def test_non_utf8_path_segment_settings_unicode_path_segments_fails(self): + defaultkw = {'unicode_path_segments':True} + settings = DummySettings(**defaultkw) + from repoze.bfg.interfaces import ISettings + import zope.component + gsm = zope.component.getGlobalSiteManager() + gsm.registerUtility(settings, ISettings) + foo = DummyContext() + root = DummyContext(foo) + 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) + + def test_non_utf8_path_segment_str_path_segments_succeeds(self): + defaultkw = {'unicode_path_segments':False} + settings = DummySettings(**defaultkw) + from repoze.bfg.interfaces import ISettings + import zope.component + gsm = zope.component.getGlobalSiteManager() + gsm.registerUtility(settings, ISettings) + foo = DummyContext() + root = DummyContext(foo) + policy = self._makeOne(root) + segment = unicode('LaPe\xc3\xb1a', 'utf-8').encode('utf-16') + environ = self._getEnviron(PATH_INFO='/%s' % segment) + ctx, name, subpath = policy(environ) # test is: this doesn't fail + class FindInterfaceTests(unittest.TestCase): def _callFUT(self, context, iface): from repoze.bfg.traversal import find_interface @@ -422,3 +458,6 @@ class DummyContext(object): class DummyRequest: application_url = 'http://example.com:5432/' +class DummySettings: + def __init__(self, **kw): + self.__dict__.update(kw) |
