diff options
Diffstat (limited to 'tests/generic_views/test_edit.py')
| -rw-r--r-- | tests/generic_views/test_edit.py | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py index d8e0193574..b61a11086a 100644 --- a/tests/generic_views/test_edit.py +++ b/tests/generic_views/test_edit.py @@ -5,7 +5,7 @@ import warnings from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse from django import forms -from django.test import TestCase, override_settings +from django.test import TestCase, ignore_warnings, override_settings from django.test.client import RequestFactory from django.utils.deprecation import RemovedInDjango20Warning from django.views.generic.base import View @@ -143,13 +143,24 @@ class CreateViewTests(TestCase): self.assertRedirects(res, 'http://testserver/edit/authors/create/') self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) + @ignore_warnings(category=RemovedInDjango20Warning) def test_create_with_interpolated_redirect(self): - res = self.client.post('/edit/authors/create/interpolate_redirect/', - {'name': 'Randall Munroe', 'slug': 'randall-munroe'}) + res = self.client.post( + '/edit/authors/create/interpolate_redirect/', + {'name': 'Randall Munroe', 'slug': 'randall-munroe'} + ) self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) self.assertEqual(res.status_code, 302) - pk = Author.objects.all()[0].pk + pk = Author.objects.first().pk self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % pk) + # Also test with escaped chars in URL + res = self.client.post( + '/edit/authors/create/interpolate_redirect_nonascii/', + {'name': 'John Doe', 'slug': 'john-doe'} + ) + self.assertEqual(res.status_code, 302) + pk = Author.objects.get(name='John Doe').pk + self.assertRedirects(res, 'http://testserver/%C3%A9dit/author/{}/update/'.format(pk)) def test_create_with_special_properties(self): res = self.client.get('/edit/authors/create/special/') @@ -272,17 +283,28 @@ class UpdateViewTests(TestCase): self.assertRedirects(res, 'http://testserver/edit/authors/create/') self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>']) + @ignore_warnings(category=RemovedInDjango20Warning) def test_update_with_interpolated_redirect(self): a = Author.objects.create( name='Randall Munroe', slug='randall-munroe', ) - res = self.client.post('/edit/author/%d/update/interpolate_redirect/' % a.pk, - {'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'}) + res = self.client.post( + '/edit/author/%d/update/interpolate_redirect/' % a.pk, + {'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'} + ) self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>']) self.assertEqual(res.status_code, 302) - pk = Author.objects.all()[0].pk + pk = Author.objects.first().pk self.assertRedirects(res, 'http://testserver/edit/author/%d/update/' % pk) + # Also test with escaped chars in URL + res = self.client.post( + '/edit/author/%d/update/interpolate_redirect_nonascii/' % a.pk, + {'name': 'John Doe', 'slug': 'john-doe'} + ) + self.assertEqual(res.status_code, 302) + pk = Author.objects.get(name='John Doe').pk + self.assertRedirects(res, 'http://testserver/%C3%A9dit/author/{}/update/'.format(pk)) def test_update_with_special_properties(self): a = Author.objects.create( @@ -368,12 +390,18 @@ class DeleteViewTests(TestCase): self.assertRedirects(res, 'http://testserver/edit/authors/create/') self.assertQuerysetEqual(Author.objects.all(), []) + @ignore_warnings(category=RemovedInDjango20Warning) def test_delete_with_interpolated_redirect(self): a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) res = self.client.post('/edit/author/%d/delete/interpolate_redirect/' % a.pk) self.assertEqual(res.status_code, 302) self.assertRedirects(res, 'http://testserver/edit/authors/create/?deleted=%d' % a.pk) self.assertQuerysetEqual(Author.objects.all(), []) + # Also test with escaped chars in URL + a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) + res = self.client.post('/edit/author/{}/delete/interpolate_redirect_nonascii/'.format(a.pk)) + self.assertEqual(res.status_code, 302) + self.assertRedirects(res, 'http://testserver/%C3%A9dit/authors/create/?deleted={}'.format(a.pk)) def test_delete_with_special_properties(self): a = Author.objects.create(**{'name': 'Randall Munroe', 'slug': 'randall-munroe'}) |
