summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/admin_custom_urls/models.py37
-rw-r--r--tests/regressiontests/admin_custom_urls/tests.py46
2 files changed, 82 insertions, 1 deletions
diff --git a/tests/regressiontests/admin_custom_urls/models.py b/tests/regressiontests/admin_custom_urls/models.py
index a5b4983b09..b9b3285463 100644
--- a/tests/regressiontests/admin_custom_urls/models.py
+++ b/tests/regressiontests/admin_custom_urls/models.py
@@ -50,3 +50,40 @@ class ActionAdmin(admin.ModelAdmin):
admin.site.register(Action, ActionAdmin)
+
+
+class Person(models.Model):
+ nick = models.CharField(max_length=20)
+
+
+class PersonAdmin(admin.ModelAdmin):
+ """A custom ModelAdmin that customizes the deprecated post_url_continue
+ argument to response_add()"""
+ def response_add(self, request, obj, post_url_continue='../%s/continue/',
+ continue_url=None, add_url=None, hasperm_url=None,
+ noperm_url=None):
+ return super(PersonAdmin, self).response_add(request, obj,
+ post_url_continue,
+ continue_url, add_url,
+ hasperm_url, noperm_url)
+
+
+admin.site.register(Person, PersonAdmin)
+
+
+class City(models.Model):
+ name = models.CharField(max_length=20)
+
+
+class CityAdmin(admin.ModelAdmin):
+ """A custom ModelAdmin that redirects to the changelist when the user
+ presses the 'Save and add another' button when adding a model instance."""
+ def response_add(self, request, obj,
+ add_another_url='admin:admin_custom_urls_city_changelist',
+ **kwargs):
+ return super(CityAdmin, self).response_add(request, obj,
+ add_another_url=add_another_url,
+ **kwargs)
+
+
+admin.site.register(City, CityAdmin)
diff --git a/tests/regressiontests/admin_custom_urls/tests.py b/tests/regressiontests/admin_custom_urls/tests.py
index 3e9cf28965..87c72e2e71 100644
--- a/tests/regressiontests/admin_custom_urls/tests.py
+++ b/tests/regressiontests/admin_custom_urls/tests.py
@@ -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