diff options
Diffstat (limited to 'tests/regressiontests/views')
-rw-r--r-- | tests/regressiontests/views/tests/__init__.py | 1 | ||||
-rw-r--r-- | tests/regressiontests/views/tests/generic/simple.py | 38 | ||||
-rw-r--r-- | tests/regressiontests/views/urls.py | 10 |
3 files changed, 48 insertions, 1 deletions
diff --git a/tests/regressiontests/views/tests/__init__.py b/tests/regressiontests/views/tests/__init__.py index 697968ee52..edd533e175 100644 --- a/tests/regressiontests/views/tests/__init__.py +++ b/tests/regressiontests/views/tests/__init__.py @@ -2,6 +2,7 @@ from debug import * from defaults import * from generic.create_update import * from generic.date_based import * +from generic.simple import * from i18n import * from specials import * from static import * diff --git a/tests/regressiontests/views/tests/generic/simple.py b/tests/regressiontests/views/tests/generic/simple.py new file mode 100644 index 0000000000..f94b3da439 --- /dev/null +++ b/tests/regressiontests/views/tests/generic/simple.py @@ -0,0 +1,38 @@ +# coding: utf-8 + +from django.test import TestCase + +class RedirectToTest(TestCase): + def test_redirect_to_returns_permanent_redirect(self): + "simple.redirect_to returns a permanent redirect (301) by default" + response = self.client.get('/views/simple/redirect_to/') + self.assertEqual(response.status_code, 301) + self.assertEqual('http://testserver/views/simple/target/', response['Location']) + + def test_redirect_to_can_return_a_temporary_redirect(self): + "simple.redirect_to returns a temporary redirect (302) when explicitely asked to" + response = self.client.get('/views/simple/redirect_to_temp/') + self.assertEqual(response.status_code, 302) + self.assertEqual('http://testserver/views/simple/target/', response['Location']) + + def test_redirect_to_on_empty_url_returns_gone(self): + "simple.redirect_to returns resource gone (410) when given a None url" + response = self.client.get('/views/simple/redirect_to_none/') + self.assertEqual(response.status_code, 410) + + def test_redirect_to_allows_formatted_url_string(self): + "simple.redirect_to uses string interpolation on target url for keyword args" + response = self.client.get('/views/simple/redirect_to_arg/42/') + self.assertEqual(response.status_code, 301) + self.assertEqual('http://testserver/views/simple/target_arg/42/', response['Location']) + + def test_redirect_to_allows_query_string_to_be_passed(self): + "simple.redirect_to configured with query_string=True passes on any query string" + # the default is to not forward the query string + response = self.client.get('/views/simple/redirect_to/?param1=foo¶m2=bar') + self.assertEqual(response.status_code, 301) + self.assertEqual('http://testserver/views/simple/target/', response['Location']) + # views configured with query_string=True however passes the query string along + response = self.client.get('/views/simple/redirect_to_query/?param1=foo¶m2=bar') + self.assertEqual(response.status_code, 301) + self.assertEqual('http://testserver/views/simple/target/?param1=foo¶m2=bar', response['Location']) diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py index f5675d0e28..b42700baeb 100644 --- a/tests/regressiontests/views/urls.py +++ b/tests/regressiontests/views/urls.py @@ -77,7 +77,6 @@ urlpatterns += patterns('django.views.generic.date_based', ) # crud generic views. - urlpatterns += patterns('django.views.generic.create_update', (r'^create_update/member/create/article/$', 'create_object', dict(login_required=True, model=Article)), @@ -123,3 +122,12 @@ urlpatterns += patterns('regressiontests.views.views', url(r'view_exception/(?P<n>\d+)/$', 'view_exception', name='view_exception'), url(r'template_exception/(?P<n>\d+)/$', 'template_exception', name='template_exception'), ) + +# simple generic views. +urlpatterns += patterns('django.views.generic.simple', + (r'^simple/redirect_to/$', 'redirect_to', dict(url='/views/simple/target/')), + (r'^simple/redirect_to_temp/$', 'redirect_to', dict(url='/views/simple/target/', permanent=False)), + (r'^simple/redirect_to_none/$', 'redirect_to', dict(url=None)), + (r'^simple/redirect_to_arg/(?P<id>\d+)/$', 'redirect_to', dict(url='/views/simple/target_arg/%(id)s/')), + (r'^simple/redirect_to_query/$', 'redirect_to', dict(url='/views/simple/target/', query_string=True)), +) |