Skip to content

Commit

Permalink
Merge pull request #21 from minervaproject/fix-site-import
Browse files Browse the repository at this point in the history
Correct check for custom admin sites
  • Loading branch information
walterrenner authored Feb 16, 2018
2 parents a68c99b + a420f7c commit f852555
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 2 additions & 3 deletions hijack_admin/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from django.core.checks import Error, Warning, register
from django.conf.global_settings import AUTH_USER_MODEL as DEFAULT_AUTH_USER_MODEL
from django.conf import settings
from django.contrib.admin.sites import site
from django.contrib import admin
from django.contrib.auth import get_user_model

from hijack import settings as hijack_settings


def _using_hijack_admin_mixin():
from hijack_admin.admin import HijackUserAdminMixin
user_admin_class = type(site._registry.get(get_user_model(), None))
user_admin_class = type(admin.site._registry.get(get_user_model(), None))
return issubclass(user_admin_class, HijackUserAdminMixin)


Expand All @@ -29,7 +29,6 @@ def check_get_requests_allowed(app_configs, **kwargs):


def check_custom_user_model(app_configs, **kwargs):
from hijack_admin.admin import HijackUserAdminMixin
warnings = []
if (settings.AUTH_USER_MODEL != DEFAULT_AUTH_USER_MODEL and
not _using_hijack_admin_mixin()):
Expand Down
19 changes: 17 additions & 2 deletions hijack_admin/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from hijack_admin.admin import HijackUserAdmin
from hijack_admin.tests.test_app.models import BasicModel
from hijack.tests.utils import SettingsOverride

if django.VERSION < (1, 7):
Expand All @@ -19,7 +18,6 @@
from hijack_admin import checks
from hijack_admin.apps import HijackAdminConfig


class ChecksTests(TestCase):

def test_check_get_requests_allowed(self):
Expand Down Expand Up @@ -73,3 +71,20 @@ def test_check_custom_user_model_default_admin(self):
self.assertEqual(warnings, expected_warnings)

admin.site.unregister(get_user_model())

@override_settings(AUTH_USER_MODEL='test_app.BasicModel')
def test_check_custom_user_model_custom_admin(self):
class CustomAdminSite(admin.AdminSite):
pass

_default_site = admin.site
admin.site = CustomAdminSite()
admin.autodiscover()

admin.site.register(get_user_model(), HijackUserAdmin)

warnings = checks.check_custom_user_model(HijackAdminConfig)
self.assertFalse(warnings)

admin.site.unregister(get_user_model())
admin.site = _default_site

0 comments on commit f852555

Please sign in to comment.