Improved test coverage of contrib/admin/checks.py.

This commit is contained in:
Anton Samarchyan 2017-06-02 18:44:34 -04:00 committed by Tim Graham
parent 7c9a833301
commit 2b53c8377d
2 changed files with 64 additions and 0 deletions

View File

@ -64,6 +64,10 @@ class SystemChecksTestCase(SimpleTestCase):
]
self.assertEqual(errors, expected)
@override_settings(TEMPLATES=[])
def test_no_template_engines(self):
self.assertEqual(admin.checks.check_dependencies(), [])
@override_settings(
INSTALLED_APPS=[
'django.contrib.admin',
@ -138,6 +142,31 @@ class SystemChecksTestCase(SimpleTestCase):
]
self.assertEqual(errors, expected)
def test_list_editable_not_a_list_or_tuple(self):
class SongAdmin(admin.ModelAdmin):
list_editable = 'test'
self.assertEqual(SongAdmin(Song, AdminSite()).check(), [
checks.Error(
"The value of 'list_editable' must be a list or tuple.",
obj=SongAdmin,
id='admin.E120',
)
])
def test_list_editable_missing_field(self):
class SongAdmin(admin.ModelAdmin):
list_editable = ('test',)
self.assertEqual(SongAdmin(Song, AdminSite()).check(), [
checks.Error(
"The value of 'list_editable[0]' refers to 'test', which is "
"not an attribute of 'admin_checks.Song'.",
obj=SongAdmin,
id='admin.E121',
)
])
def test_readonly_and_editable(self):
class SongAdmin(admin.ModelAdmin):
readonly_fields = ["original_release"]
@ -572,6 +601,18 @@ class SystemChecksTestCase(SimpleTestCase):
]
self.assertEqual(errors, expected)
def test_readonly_fields_not_list_or_tuple(self):
class SongAdmin(admin.ModelAdmin):
readonly_fields = 'test'
self.assertEqual(SongAdmin(Song, AdminSite()).check(), [
checks.Error(
"The value of 'readonly_fields' must be a list or tuple.",
obj=SongAdmin,
id='admin.E034',
)
])
def test_extra(self):
class SongAdmin(admin.ModelAdmin):
def awesome_song(self, instance):

View File

@ -366,6 +366,17 @@ class RadioFieldsCheckTests(CheckTestCase):
class PrepopulatedFieldsCheckTests(CheckTestCase):
def test_not_list_or_tuple(self):
class TestModelAdmin(ModelAdmin):
prepopulated_fields = {'slug': 'test'}
self.assertIsInvalid(
TestModelAdmin, ValidationTestModel,
'The value of \'prepopulated_fields["slug"]\' must be a list '
'or tuple.',
'admin.E029'
)
def test_not_dictionary(self):
class TestModelAdmin(ModelAdmin):
prepopulated_fields = ()
@ -1130,3 +1141,15 @@ class ListDisplayEditableTests(CheckTestCase):
"'list_display_links' is set.",
id='admin.E124',
)
def test_both_list_editable_and_list_display_links(self):
class ProductAdmin(ModelAdmin):
list_editable = ('name',)
list_display = ('name',)
list_display_links = ('name',)
self.assertIsInvalid(
ProductAdmin, ValidationTestModel,
"The value of 'name' cannot be in both 'list_editable' and "
"'list_display_links'.",
id='admin.E123',
)