Skip to content

Commit 0e11b3e

Browse files
committed
Add idempotence tests for canonicalize_url
1 parent efbe75e commit 0e11b3e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/test_utils_url.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,19 @@ def test_canonicalize_parse_url(http://github.com/self):
252252
self.assertEqual(canonicalize_url(parse_url("http://www.example.com/a%a3do?q=r%c3%a9sum%c3%a9")),
253253
"http://www.example.com/a%A3do?q=r%C3%A9sum%C3%A9")
254254

255+
def test_canonicalize_url_idempotence(self):
256+
for url, enc in [(u'http://www.bücher.de/résumé?q=résumé', 'utf8'),
257+
(u'http://www.example.com/résumé?q=résumé', 'latin1'),
258+
(u'http://www.example.com/résumé?country=Россия', 'cp1251'),
259+
(u'http://はじめよう.みんな/?query=サ&maxResults=5', 'iso2022jp')]:
260+
canonicalized = canonicalize_url(url, encoding=enc)
261+
262+
# if we canonicalize again, we ge the same result
263+
self.assertEqual(canonicalize_url(canonicalized, encoding=enc), canonicalized)
264+
265+
# without encoding, already canonicalized URL is canonicalized identically
266+
self.assertEqual(canonicalize_url(canonicalized), canonicalized)
267+
255268

256269
class AddHttpIfNoScheme(unittest.TestCase):
257270

0 commit comments

Comments
 (0)