summaryrefslogtreecommitdiff
path: root/tests/admin_views
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-02-07 17:55:47 +0100
committerClaude Paroz <claude@2xlibre.net>2015-02-14 11:19:55 +0100
commit1791a7e75af8c9e7ca54425592379fd1f840fe88 (patch)
tree5c7da7419443c0aaaa530919700659891e3ae2a8 /tests/admin_views
parent47ee7b48adbcc0dafc3404034286c5fcbcd1cea6 (diff)
Fixed #15779 -- Allowed 'add' primary key in admin edition
Thanks Marwan Alsabbagh for the report, and Simon Charette and Tim Graham for the reviews.
Diffstat (limited to 'tests/admin_views')
-rw-r--r--tests/admin_views/admin.py2
-rw-r--r--tests/admin_views/tests.py18
2 files changed, 17 insertions, 3 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index c044a6ac21..aa5a336f4f 100644
--- a/tests/admin_views/admin.py
+++ b/tests/admin_views/admin.py
@@ -693,7 +693,7 @@ class UnchangeableObjectAdmin(admin.ModelAdmin):
def get_urls(self):
# Disable change_view, but leave other urls untouched
urlpatterns = super(UnchangeableObjectAdmin, self).get_urls()
- return [p for p in urlpatterns if not p.name.endswith("_change")]
+ return [p for p in urlpatterns if p.name and not p.name.endswith("_change")]
def callable_on_unknown(obj):
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index a2c742f3ed..4b662a948e 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -137,6 +137,15 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
response = self.client.get(reverse('admin:admin_views_section_change', args=('abc',)))
self.assertEqual(response.status_code, 404)
+ def test_basic_edit_GET_old_url_redirect(self):
+ """
+ The change URL changed in Django 1.9, but the old one still redirects.
+ """
+ response = self.client.get(
+ reverse('admin:admin_views_section_change', args=(1,)).replace('change/', '')
+ )
+ self.assertRedirects(response, reverse('admin:admin_views_section_change', args=(1,)))
+
def test_basic_inheritance_GET_string_PK(self):
"""
Ensure GET on the change_view works on inherited models (returns an
@@ -2022,8 +2031,8 @@ class AdminViewStringPrimaryKeyTest(TestCase):
self.assertContains(response, should_contain)
def test_url_conflicts_with_add(self):
- "A model with a primary key that ends with add should be visible"
- add_model = ModelWithStringPrimaryKey(pk="i have something to add")
+ "A model with a primary key that ends with add or is `add` should be visible"
+ add_model = ModelWithStringPrimaryKey.objects.create(pk="i have something to add")
add_model.save()
response = self.client.get(
reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(add_model.pk),))
@@ -2031,6 +2040,11 @@ class AdminViewStringPrimaryKeyTest(TestCase):
should_contain = """<h1>Change model with string primary key</h1>"""
self.assertContains(response, should_contain)
+ add_model2 = ModelWithStringPrimaryKey.objects.create(pk="add")
+ add_url = reverse('admin:admin_views_modelwithstringprimarykey_add')
+ change_url = reverse('admin:admin_views_modelwithstringprimarykey_change', args=(quote(add_model2.pk),))
+ self.assertNotEqual(add_url, change_url)
+
def test_url_conflicts_with_delete(self):
"A model with a primary key that ends with delete should be visible"
delete_model = ModelWithStringPrimaryKey(pk="delete")