diff options
author | Adam Chainz <adam@adamj.eu> | 2017-01-02 16:42:27 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2017-01-10 07:02:13 -0500 |
commit | d57ecf40ebad564fafa36825b17b6c15f13cfc01 (patch) | |
tree | 11966215b202bdbe3fd4cd6afde28de983eca496 /tests/admin_checks | |
parent | ed8c0c941df0f321fb5751db572a9ec773d5118a (diff) | |
download | django-d57ecf40ebad564fafa36825b17b6c15f13cfc01.tar.gz |
Fixed #27673 -- Made admin's checks run at check time instead of during registration.
Thanks Morgan Aubert for the test.
Diffstat (limited to 'tests/admin_checks')
-rw-r--r-- | tests/admin_checks/tests.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py index fa1bcc1518..d243a56640 100644 --- a/tests/admin_checks/tests.py +++ b/tests/admin_checks/tests.py @@ -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): |