summaryrefslogtreecommitdiff
path: root/tests/admin_checks
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/admin_checks
parent2ebccebf0609229317c2f5b9a76664dc216f27eb (diff)
downloaddjango-23b781cc3d17f12c5158f781b2c8cd9d47550c20.tar.gz
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/admin_checks')
-rw-r--r--tests/admin_checks/tests.py34
1 files changed, 34 insertions, 0 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)