summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAaron France <aaron.l.france@gmail.com>2014-02-15 11:28:09 +0100
committerBaptiste Mispelon <bmispelon@gmail.com>2014-02-15 15:01:44 +0100
commit23b781cc3d17f12c5158f781b2c8cd9d47550c20 (patch)
treea832668067ead7c6496a820c3e8b65809e8dfe05 /tests
parent2ebccebf0609229317c2f5b9a76664dc216f27eb (diff)
Fixed #22018 -- Fixed checks for ModelAdmin.fields not handling sub-lists.
Flatten a level of sublists before checking for duplicate fields. When given sublists such as: ```python class FooAdmin(admin.ModelAdmin): fields = ('one', ('one', 'two')) ``` The previous code did not correctly detect the duplicated 'one' field. Thanks to jwa for the report.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_checks/tests.py34
-rw-r--r--tests/admin_util/tests.py15
2 files changed, 47 insertions, 2 deletions
diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py
index ba9faea03f..109161ebba 100644
--- a/tests/admin_checks/tests.py
+++ b/tests/admin_checks/tests.py
@@ -463,3 +463,37 @@ class SystemChecksTestCase(TestCase):
)
]
self.assertEqual(errors, expected)
+
+ def test_check_sublists_for_duplicates(self):
+ class MyModelAdmin(admin.ModelAdmin):
+ fields = ['state', ['state']]
+
+ errors = MyModelAdmin.check(model=Song)
+ expected = [
+ checks.Error(
+ 'There are duplicate field(s) in "fields".',
+ hint=None,
+ obj=MyModelAdmin,
+ id='admin.E006'
+ )
+ ]
+ self.assertEqual(errors, expected)
+
+ def test_check_fieldset_sublists_for_duplicates(self):
+ class MyModelAdmin(admin.ModelAdmin):
+ fieldsets = [
+ (None, {
+ 'fields': ['title', 'album', ('title', 'album')]
+ }),
+ ]
+
+ errors = MyModelAdmin.check(model=Song)
+ expected = [
+ checks.Error(
+ 'There are duplicate field(s) in "fieldsets[0][1]".',
+ hint=None,
+ obj=MyModelAdmin,
+ id='admin.E012'
+ )
+ ]
+ self.assertEqual(errors, expected)
diff --git a/tests/admin_util/tests.py b/tests/admin_util/tests.py
index 4cb2d843fb..20980efffa 100644
--- a/tests/admin_util/tests.py
+++ b/tests/admin_util/tests.py
@@ -5,8 +5,8 @@ from datetime import datetime
from django.conf import settings
from django.contrib import admin
from django.contrib.admin import helpers
-from django.contrib.admin.utils import (display_for_field, flatten_fieldsets,
- label_for_field, lookup_field, NestedObjects)
+from django.contrib.admin.utils import (display_for_field, flatten,
+ flatten_fieldsets, label_for_field, lookup_field, NestedObjects)
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
from django.contrib.sites.models import Site
from django.db import models, DEFAULT_DB_ALIAS
@@ -323,6 +323,17 @@ class UtilTests(SimpleTestCase):
self.assertHTMLEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
'<label for="id_cb" class="vCheckboxLabel required inline">&amp;cb</label>')
+ def test_flatten(self):
+ flat_all = ['url', 'title', 'content', 'sites']
+ inputs = (
+ ((), []),
+ (('url', 'title', ('content', 'sites')), flat_all),
+ (('url', 'title', 'content', 'sites'), flat_all),
+ ((('url', 'title'), ('content', 'sites')), flat_all)
+ )
+ for orig, expected in inputs:
+ self.assertEqual(flatten(orig), expected)
+
def test_flatten_fieldsets(self):
"""
Regression test for #18051