PageRenderTime 67ms CodeModel.GetById 59ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/regressiontests/views/tests/generic/simple.py

https://code.google.com/p/mango-py/
Python | 38 lines | 29 code | 6 blank | 3 comment | 0 complexity | eb2ea34cf2c5bf9da4415e7cded84b15 MD5 | raw file
 1# coding: utf-8
 2
 3from django.test import TestCase
 4
 5class RedirectToTest(TestCase):
 6    def test_redirect_to_returns_permanent_redirect(self):
 7        "simple.redirect_to returns a permanent redirect (301) by default"
 8        response = self.client.get('/views/simple/redirect_to/')
 9        self.assertEqual(response.status_code, 301)
10        self.assertEqual('http://testserver/views/simple/target/', response['Location'])
11
12    def test_redirect_to_can_return_a_temporary_redirect(self):
13        "simple.redirect_to returns a temporary redirect (302) when explicitely asked to"
14        response = self.client.get('/views/simple/redirect_to_temp/')
15        self.assertEqual(response.status_code, 302)
16        self.assertEqual('http://testserver/views/simple/target/', response['Location'])
17
18    def test_redirect_to_on_empty_url_returns_gone(self):
19        "simple.redirect_to returns resource gone (410) when given a None url"
20        response = self.client.get('/views/simple/redirect_to_none/')
21        self.assertEqual(response.status_code, 410)
22
23    def test_redirect_to_allows_formatted_url_string(self):
24        "simple.redirect_to uses string interpolation on target url for keyword args"
25        response = self.client.get('/views/simple/redirect_to_arg/42/')
26        self.assertEqual(response.status_code, 301)
27        self.assertEqual('http://testserver/views/simple/target_arg/42/', response['Location'])
28
29    def test_redirect_to_allows_query_string_to_be_passed(self):
30        "simple.redirect_to configured with query_string=True passes on any query string"
31        # the default is to not forward the query string
32        response = self.client.get('/views/simple/redirect_to/?param1=foo&param2=bar')
33        self.assertEqual(response.status_code, 301)
34        self.assertEqual('http://testserver/views/simple/target/', response['Location'])
35        # views configured with query_string=True however passes the query string along
36        response = self.client.get('/views/simple/redirect_to_query/?param1=foo&param2=bar')
37        self.assertEqual(response.status_code, 301)
38        self.assertEqual('http://testserver/views/simple/target/?param1=foo&param2=bar', response['Location'])