diff --git a/admin_interface/apps.py b/admin_interface/apps.py index c46c4e5..b8a4984 100644 --- a/admin_interface/apps.py +++ b/admin_interface/apps.py @@ -11,7 +11,9 @@ class AdminInterfaceConfig(AppConfig): def ready(self): + from admin_interface import settings from admin_interface.models import Theme + settings.check_installed_apps() post_migrate.connect( Theme.post_migrate_handler, sender=self) diff --git a/admin_interface/settings.py b/admin_interface/settings.py new file mode 100644 index 0000000..4855371 --- /dev/null +++ b/admin_interface/settings.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +import django +from django.conf import settings +from django.core.exceptions import ImproperlyConfigured + + +def check_installed_apps(): + dj_version = django.VERSION + installed_apps = settings.INSTALLED_APPS + + if 'colorfield' not in installed_apps: + raise ImproperlyConfigured( + '\'colorfield\' needed, ' + 'add it to settings.INSTALLED_APPS.') + + if dj_version < (1, 9): + if 'flat' not in installed_apps: + raise ImproperlyConfigured( + '\'flat\' needed before django 1.9, ' + 'add it to settings.INSTALLED_APPS.') + else: + if 'flat' in installed_apps: + raise ImproperlyConfigured( + '\'flat\' not needed since django 1.9, ' + 'remove it from settings.INSTALLED_APPS.') + + if dj_version < (2, 0): + if 'flat_responsive' not in installed_apps: + raise ImproperlyConfigured( + '\'flat_responsive\' needed before django 2.0, ' + 'add it to settings.INSTALLED_APPS.') + else: + if 'flat_responsive' in installed_apps: + raise ImproperlyConfigured( + '\'flat_responsive\' not needed since django 2.0, ' + 'remove it from settings.INSTALLED_APPS.') + diff --git a/tests/settings.py b/tests/settings.py index f1937d9..ef33456 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -9,13 +9,25 @@ SECRET_KEY = 'django-admin-interface' ALLOWED_HOSTS = ['*'] +# Application definition INSTALLED_APPS = [ - 'admin_interface', - 'flat_responsive', - 'flat', #if django version < 1.9 'colorfield', +] +if django.VERSION < (1, 9): + # ONLY if django version < 1.9 + INSTALLED_APPS += [ + 'flat', + ] + +if django.VERSION < (2, 0): + # ONLY if django version < 2.0 + INSTALLED_APPS += [ + 'flat_responsive', + ] + +INSTALLED_APPS += [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..1396afc --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- + +import django +from django.conf import settings +from django.core.exceptions import ImproperlyConfigured +from django.test import override_settings, TestCase + +from admin_interface.settings import check_installed_apps + + +class AdminInterfaceSettingsTestCase(TestCase): + + DJANGO_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.messages', + 'django.contrib.sessions', + ] + + def setUp(self): + pass + + def tearDown(self): + pass + + def __test_installed_apps(self): + dj_version = django.VERSION + installed_apps = settings.INSTALLED_APPS + + if 'colorfield' not in installed_apps: + self.assertRaises(ImproperlyConfigured, check_installed_apps) + + elif 'flat' not in installed_apps and dj_version < (1, 9): + self.assertRaises(ImproperlyConfigured, check_installed_apps) + + elif 'flat' in installed_apps and dj_version >= (1, 9): + self.assertRaises(ImproperlyConfigured, check_installed_apps) + + elif 'flat_responsive' not in installed_apps and dj_version < (2, 0): + self.assertRaises(ImproperlyConfigured, check_installed_apps) + + elif 'flat_responsive' in installed_apps and dj_version >= (2, 0): + self.assertRaises(ImproperlyConfigured, check_installed_apps) + + else: + check_installed_apps() + + @override_settings( + INSTALLED_APPS = [ + 'admin_interface', + 'colorfield', + 'flat', + 'flat_responsive', + ] + DJANGO_APPS + ) + def test_installed_apps_all(self): + self.__test_installed_apps() + + @override_settings( + INSTALLED_APPS = [ + 'admin_interface', + # 'colorfield', + 'flat', + 'flat_responsive', + ] + DJANGO_APPS + ) + def test_installed_apps_no_colorfield(self): + self.__test_installed_apps() + + @override_settings( + INSTALLED_APPS = [ + 'admin_interface', + 'colorfield', + # 'flat', + 'flat_responsive', + ] + DJANGO_APPS + ) + def test_installed_apps_no_flat(self): + self.__test_installed_apps() + + @override_settings( + INSTALLED_APPS = [ + 'admin_interface', + 'colorfield', + 'flat', + # 'flat_responsive', + ] + DJANGO_APPS + ) + def test_installed_apps_no_flat_responsive(self): + self.__test_installed_apps() +