| | 63 | |
|---|
| | 64 | class AssertRedirectsTests(TestCase): |
|---|
| | 65 | def test_redirect_page(self): |
|---|
| | 66 | "An assertion is raised if the original page couldn't be retrieved as expected" |
|---|
| | 67 | # This page will redirect with code 301, not 302 |
|---|
| | 68 | response = self.client.get('/test_client/permanent_redirect_view/') |
|---|
| | 69 | try: |
|---|
| | 70 | self.assertRedirects(response, '/test_client/get_view/') |
|---|
| | 71 | except AssertionError, e: |
|---|
| | 72 | self.assertEquals(str(e), "Response didn't redirect as expected: Reponse code was 301 (expected 302)") |
|---|
| | 73 | |
|---|
| | 74 | def test_incorrect_target(self): |
|---|
| | 75 | "An assertion is raised if the response redirects to another target" |
|---|
| | 76 | response = self.client.get('/test_client/permanent_redirect_view/') |
|---|
| | 77 | try: |
|---|
| | 78 | # Should redirect to get_view |
|---|
| | 79 | self.assertRedirects(response, '/test_client/some_view/') |
|---|
| | 80 | except AssertionError, e: |
|---|
| | 81 | self.assertEquals(str(e), "Response didn't redirect as expected: Reponse code was 301 (expected 302)") |
|---|
| | 83 | def test_target_page(self): |
|---|
| | 84 | "An assertion is raised if the reponse redirect target cannot be retrieved as expected" |
|---|
| | 85 | response = self.client.get('/test_client/double_redirect_view/') |
|---|
| | 86 | try: |
|---|
| | 87 | # The redirect target responds with a 301 code, not 200 |
|---|
| | 88 | self.assertRedirects(response, '/test_client/permanent_redirect_view/') |
|---|
| | 89 | except AssertionError, e: |
|---|
| | 90 | self.assertEquals(str(e), "Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)") |
|---|
| | 91 | |
|---|