2009-04-12 11:50:47 +08:00
|
|
|
# coding: utf-8
|
|
|
|
from django.test import TestCase
|
|
|
|
|
2011-04-02 21:27:40 +08:00
|
|
|
|
2009-04-12 11:50:47 +08:00
|
|
|
class URLHandling(TestCase):
|
|
|
|
"""
|
|
|
|
Tests for URL handling in views and responses.
|
|
|
|
"""
|
2011-04-02 21:27:40 +08:00
|
|
|
urls = 'regressiontests.views.generic_urls'
|
|
|
|
redirect_target = "/%E4%B8%AD%E6%96%87/target/"
|
|
|
|
|
2010-03-03 03:37:48 +08:00
|
|
|
def test_combining_redirect(self):
|
2009-04-12 11:50:47 +08:00
|
|
|
"""
|
|
|
|
Tests that redirecting to an IRI, requiring encoding before we use it
|
2010-03-03 03:37:48 +08:00
|
|
|
in an HTTP response, is handled correctly. In this case the arg to
|
|
|
|
HttpRedirect is ASCII but the current request path contains non-ASCII
|
|
|
|
characters so this test ensures the creation of the full path with a
|
|
|
|
base non-ASCII part is handled correctly.
|
2009-04-12 11:50:47 +08:00
|
|
|
"""
|
2011-04-02 21:27:40 +08:00
|
|
|
response = self.client.get(u'/中文/')
|
2010-03-03 03:37:48 +08:00
|
|
|
self.assertRedirects(response, self.redirect_target)
|
|
|
|
|
|
|
|
def test_nonascii_redirect(self):
|
|
|
|
"""
|
|
|
|
Tests that a non-ASCII argument to HttpRedirect is handled properly.
|
|
|
|
"""
|
2011-04-02 21:27:40 +08:00
|
|
|
response = self.client.get('/nonascii_redirect/')
|
2010-03-03 03:37:48 +08:00
|
|
|
self.assertRedirects(response, self.redirect_target)
|
|
|
|
|
|
|
|
def test_permanent_nonascii_redirect(self):
|
|
|
|
"""
|
|
|
|
Tests that a non-ASCII argument to HttpPermanentRedirect is handled
|
|
|
|
properly.
|
|
|
|
"""
|
2011-04-02 21:27:40 +08:00
|
|
|
response = self.client.get('/permanent_nonascii_redirect/')
|
2010-03-03 03:37:48 +08:00
|
|
|
self.assertRedirects(response, self.redirect_target, status_code=301)
|
2009-04-12 11:50:47 +08:00
|
|
|
|