Skip to content
Browse files

try variants of a URL (without query string, with/without trailing sl…

…ash) when initial redirect lookup fails
  • Loading branch information...
1 parent b57200f commit 9d3009ad0b282d89bac930568e4c74a811703a0e @nsh-ableton nsh-ableton committed Aug 31, 2012
Showing with 21 additions and 9 deletions.
  1. +21 −9 cms_redirects/tests.py
View
30 cms_redirects/tests.py
@@ -10,7 +10,7 @@
class TestRedirects(unittest.TestCase):
def setUp(self):
settings.APPEND_SLASH = False
-
+
self.site = Site.objects.get_current()
page = Page()
@@ -22,21 +22,21 @@ def setUp(self):
title = Title(title="Hello world!")
title.page = page
title.language = u'en'
- title.save()
-
+ title.save()
+
def test_301_page_redirect(self):
r_301_page = CMSRedirect(site=self.site, page=self.page, old_path='/301_page.php')
r_301_page.save()
-
+
c = Client()
r = c.get('/301_page.php')
self.assertEqual(r.status_code, 301)
self.assertEqual(r._headers['location'][1], 'http://testserver/')
-
+
def test_302_page_redirect(self):
r_302_page = CMSRedirect(site=self.site, page=self.page, old_path='/302_page.php', response_code='302')
r_302_page.save()
-
+
c = Client()
r = c.get('/302_page.php')
self.assertEqual(r.status_code, 302)
@@ -45,7 +45,7 @@ def test_302_page_redirect(self):
def test_301_path_redirect(self):
r_301_path = CMSRedirect(site=self.site, new_path='/', old_path='/301_path.php')
r_301_path.save()
-
+
c = Client()
r = c.get('/301_path.php')
self.assertEqual(r.status_code, 301)
@@ -54,7 +54,7 @@ def test_301_path_redirect(self):
def test_302_path_redirect(self):
r_302_path = CMSRedirect(site=self.site, new_path='/', old_path='/302_path.php', response_code='302')
r_302_path.save()
-
+
c = Client()
r = c.get('/302_path.php')
self.assertEqual(r.status_code, 302)
@@ -63,8 +63,20 @@ def test_302_path_redirect(self):
def test_410_redirect(self):
r_410 = CMSRedirect(site=self.site, old_path='/410.php', response_code='302')
r_410.save()
-
+
c = Client()
r = c.get('/410.php')
self.assertEqual(r.status_code, 410)
+ def test_redirect_can_ignore_query_string(self):
+ """
+ Set up a redirect as in the generic 301 page case, but then try to get this page with
+ a query string appended. Succeed nonetheless.
+ """
+ r_301_page = CMSRedirect(site=self.site, page=self.page, old_path='/301_page.php')
+ r_301_page.save()
+
+ c = Client()
+ r = c.get('/301_page.php?this=is&a=query&string')
+ self.assertEqual(r.status_code, 301)
+ self.assertEqual(r._headers['location'][1], 'http://testserver')

0 comments on commit 9d3009a

Please sign in to comment.
Something went wrong with that request. Please try again.