1
0
mirror of https://github.com/django/django.git synced 2025-10-28 16:16:12 +00:00

Fixed #27673 -- Made admin's checks run at check time instead of during registration.

Thanks Morgan Aubert for the test.
This commit is contained in:
Adam Chainz
2017-01-02 16:42:27 -05:00
committed by Tim Graham
parent ed8c0c941d
commit d57ecf40eb
4 changed files with 54 additions and 13 deletions

View File

@@ -7,7 +7,9 @@ from django.contrib.contenttypes.admin import GenericStackedInline
from django.core import checks
from django.test import SimpleTestCase, override_settings
from .models import Album, Book, City, Influence, Song, State, TwoAlbumFKAndAnE
from .models import (
Album, Author, Book, City, Influence, Song, State, TwoAlbumFKAndAnE,
)
class SongForm(forms.ModelForm):
@@ -52,7 +54,6 @@ class SystemChecksTestCase(SimpleTestCase):
self.assertEqual(errors, expected)
finally:
admin.site.unregister(Song)
admin.sites.system_check_errors = []
@override_settings(INSTALLED_APPS=['django.contrib.admin'])
def test_contenttypes_dependency(self):
@@ -105,7 +106,27 @@ class SystemChecksTestCase(SimpleTestCase):
self.assertEqual(errors, expected)
finally:
custom_site.unregister(Song)
admin.sites.system_check_errors = []
@override_settings(DEBUG=True)
def test_allows_checks_relying_on_other_modeladmins(self):
class MyBookAdmin(admin.ModelAdmin):
def check(self, **kwargs):
errors = super(MyBookAdmin, self).check(**kwargs)
author_admin = self.admin_site._registry.get(Author)
if author_admin is None:
errors.append('AuthorAdmin missing!')
return errors
class MyAuthorAdmin(admin.ModelAdmin):
pass
admin.site.register(Book, MyBookAdmin)
admin.site.register(Author, MyAuthorAdmin)
try:
self.assertEqual(admin.site.check(None), [])
finally:
admin.site.unregister(Book)
admin.site.unregister(Author)
def test_field_name_not_in_list_display(self):
class SongAdmin(admin.ModelAdmin):