summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_encode.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-09-23 10:24:42 +0000
committerChris McDonough <chrism@agendaless.com>2009-09-23 10:24:42 +0000
commiteb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5 (patch)
tree26afc97a9ddc53feca88bfac957bb376357edc6b /repoze/bfg/tests/test_encode.py
parent02e1fe45e4bb2d7473296d2b8c2114680d9c75c2 (diff)
downloadpyramid-eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5.tar.gz
pyramid-eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5.tar.bz2
pyramid-eb9fbf5f24b5e41cadd1eac8ca970ba819ecb6a5.zip
Features
-------- - Speed up ``repoze.bfg.encode.urlencode`` (nee' ``repoze.bfg.url.urlencode``) slightly. - Speed up ``repoze.bfg.traversal.model_path`` and ``repoze.bfg.traversal.model_path_tuple`` slightly. Internal -------- - Move ``repoze.bfg.traversal._url_quote`` into ``repoze.bfg.encode`` as ``url_quote``. Backwards Incompatibilities --------------------------- - We previously had a Unicode-aware wrapper for the ``urllib.urlencode`` function named ``repoze.bfg.url.urlencode`` which delegated to the stdlib function, but which marshalled all unicode values to utf-8 strings before calling the stdlib version. A newer replacement now lives in ``repoze.bfg.encode`` (old imports will still work). The replacement does not delegate to the stdlib. The replacement diverges from the stdlib implementation and the previous ``repoze.bfg.url`` url implementation inasmuch as its ``doseq`` argument is a decoy: it always behaves in the ``doseq=True`` way (which is the only sane behavior) for speed purposes. The old import location (``repoze.bfg.url.urlencode``) still functions and has not been deprecated.
Diffstat (limited to 'repoze/bfg/tests/test_encode.py')
-rw-r--r--repoze/bfg/tests/test_encode.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_encode.py b/repoze/bfg/tests/test_encode.py
new file mode 100644
index 000000000..364247fb3
--- /dev/null
+++ b/repoze/bfg/tests/test_encode.py
@@ -0,0 +1,61 @@
+import unittest
+
+class UrlEncodeTests(unittest.TestCase):
+ def _callFUT(self, query, doseq=False):
+ from repoze.bfg.encode import urlencode
+ return urlencode(query, doseq)
+
+ def test_ascii_only(self):
+ result = self._callFUT([('a',1), ('b',2)])
+ self.assertEqual(result, 'a=1&b=2')
+
+ def test_unicode_key(self):
+ la = unicode('LaPe\xc3\xb1a', 'utf-8')
+ result = self._callFUT([(la, 1), ('b',2)])
+ self.assertEqual(result, 'LaPe%C3%B1a=1&b=2')
+
+ def test_unicode_val_single(self):
+ la = unicode('LaPe\xc3\xb1a', 'utf-8')
+ result = self._callFUT([('a', la), ('b',2)])
+ self.assertEqual(result, 'a=LaPe%C3%B1a&b=2')
+
+ def test_unicode_val_multiple(self):
+ la = [unicode('LaPe\xc3\xb1a', 'utf-8')] * 2
+ result = self._callFUT([('a', la), ('b',2)], doseq=True)
+ self.assertEqual(result, 'a=LaPe%C3%B1a&a=LaPe%C3%B1a&b=2')
+
+ def test_dict(self):
+ result = self._callFUT({'a':1})
+ self.assertEqual(result, 'a=1')
+
+class URLQuoteTests(unittest.TestCase):
+ def _callFUT(self, val, safe=''):
+ from repoze.bfg.encode import url_quote
+ return url_quote(val, safe)
+
+ def test_it_default(self):
+ la = 'La/Pe\xc3\xb1a'
+ result = self._callFUT(la)
+ self.assertEqual(result, 'La%2FPe%C3%B1a')
+
+ def test_it_with_safe(self):
+ la = 'La/Pe\xc3\xb1a'
+ result = self._callFUT(la, '/')
+ self.assertEqual(result, 'La/Pe%C3%B1a')
+
+class TestQuotePlus(unittest.TestCase):
+ def _callFUT(self, val, safe=''):
+ from repoze.bfg.encode import quote_plus
+ return quote_plus(val, safe)
+
+ def test_it_default(self):
+ la = 'La Pe\xc3\xb1a'
+ result = self._callFUT(la)
+ self.assertEqual(result, 'La+Pe%C3%B1a')
+
+ def test_it_with_safe(self):
+ la = 'La /Pe\xc3\xb1a'
+ result = self._callFUT(la, '/')
+ self.assertEqual(result, 'La+/Pe%C3%B1a')
+
+