1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #8001 -- Made redirections after add/edit in admin customizable.

Also fixes #18310.
This commit is contained in:
Ramiro Morales
2012-10-18 20:58:52 -03:00
parent db598dd8a0
commit 0b908b92a2
4 changed files with 190 additions and 48 deletions

View File

@@ -1,12 +1,14 @@
from __future__ import absolute_import, unicode_literals
import warnings
from django.contrib.admin.util import quote
from django.core.urlresolvers import reverse
from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.utils import override_settings
from .models import Action
from .models import Action, Person, City
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
@@ -81,3 +83,45 @@ class AdminCustomUrlsTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Change action')
self.assertContains(response, 'value="path/to/html/document.html"')
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class CustomUrlsWorkflowTests(TestCase):
fixtures = ['users.json']
def setUp(self):
self.client.login(username='super', password='secret')
def tearDown(self):
self.client.logout()
def test_old_argument_deprecation(self):
"""Test reporting of post_url_continue deprecation."""
post_data = {
'nick': 'johndoe',
}
cnt = Person.objects.count()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
response = self.client.post(reverse('admin:admin_custom_urls_person_add'), post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Person.objects.count(), cnt + 1)
# We should get a DeprecationWarning
self.assertEqual(len(w), 1)
self.assertTrue(isinstance(w[0].message, DeprecationWarning))
def test_custom_add_another_redirect(self):
"""Test customizability of post-object-creation redirect URL."""
post_data = {
'name': 'Rome',
'_addanother': '1',
}
cnt = City.objects.count()
with warnings.catch_warnings(record=True) as w:
# POST to the view whose post-object-creation redir URL argument we
# are customizing (object creation)
response = self.client.post(reverse('admin:admin_custom_urls_city_add'), post_data)
self.assertEqual(City.objects.count(), cnt + 1)
# Check that it redirected to the URL we set
self.assertRedirects(response, reverse('admin:admin_custom_urls_city_changelist'))
self.assertEqual(len(w), 0) # We should get no DeprecationWarning