def test_list_setting_from_defaults_django_2_x(self):
        '''
        A list setting that exists in the django.conf.settings.global_settings
        should merge with the default, not replace it entirely.

        Since Django 2.0, MIDDLEWARE_CLASSES is removed and MIDDLEWARE has empty default.
        Simulate non-empty default by replacing the global default value.
        '''
        from django.conf import global_settings

        # Overwrite the default settings.
        old_middleware = global_settings.MIDDLEWARE
        global_settings.MIDDLEWARE = [
            'django.middleware.common.CommonMiddleware'
        ]

        try:
            self.settings_dict['INSTALLED_APPS'] = [
                'django_autoconfig.tests.app_middleware'
            ]
            autoconfig.configure_settings(self.settings_dict)
            self.assertIn('my.middleware', self.settings_dict['MIDDLEWARE'])
            self.assertIn('django.middleware.common.CommonMiddleware',
                          self.settings_dict['MIDDLEWARE'])
        finally:
            # Restore default settings to its original value.
            global_settings.MIDDLEWARE = old_middleware
Пример #2
0
 def test_importerror_from_no_parent(self):
     '''
     An import error due to the parent module not existing should be raised.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['i.do.not.exist']
     with self.assertRaises(ImportError):
         autoconfig.configure_settings(self.settings_dict)
Пример #3
0
 def test_default_setting(self):
     '''
     A setting in the DEFAULTS section should be used like merging.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_default_settings']
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['DEFAULT_SETTING'], [1, 2, 3])
 def test_contrib_autoconfig(self):
     '''
     Test autoconfig provided by us instead of the app.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django.contrib.auth']
     autoconfig.configure_settings(self.settings_dict)
     self.assertIn('django.contrib.sessions', self.settings_dict['INSTALLED_APPS'])
Пример #5
0
 def test_contrib_autoconfig(self):
     '''
     Test autoconfig provided by us instead of the app.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django.contrib.auth']
     autoconfig.configure_settings(self.settings_dict)
     self.assertIn('django.contrib.sessions', self.settings_dict['INSTALLED_APPS'])
 def test_importerror_from_no_parent(self):
     '''
     An import error due to the parent module not existing should be raised.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['i.do.not.exist']
     with self.assertRaises(ImportError):
         autoconfig.configure_settings(self.settings_dict)
 def test_default_setting(self):
     '''
     A setting in the DEFAULTS section should be used like merging.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_default_settings']
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['DEFAULT_SETTING'], [1, 2, 3])
Пример #8
0
 def test_booleans(self):
     '''
     Things we can't merge just get replaced.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_boolean']
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['DEBUG'], True)
Пример #9
0
 def test_inconsistency(self):
     '''
     Check for required inconsistencies.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_boolean', 'django_autoconfig.tests.app_boolean_inconsistent']
     with self.assertRaises(ImproperlyConfigured):
         autoconfig.configure_settings(self.settings_dict)
 def test_inconsistency(self):
     '''
     Check for required inconsistencies.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_boolean', 'django_autoconfig.tests.app_boolean_inconsistent']
     with self.assertRaises(ImproperlyConfigured):
         autoconfig.configure_settings(self.settings_dict)
 def test_booleans(self):
     '''
     Things we can't merge just get replaced.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_boolean']
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['DEBUG'], True)
Пример #12
0
 def test_django18_templates(self):
     '''
     Check that the Django 1.8 TEMPLATES setting works.
     '''
     self.settings_dict['INSTALLED_APPS'] = [
         'django_autoconfig.tests.app_18templates1',
         'django_autoconfig.tests.app_18templates2',
     ]
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(
         self.settings_dict['TEMPLATES'],
         [
             {
                 'BACKEND':
                 'django.template.backends.django.DjangoTemplates',
                 'APP_DIRS': True,
                 'OPTIONS': {
                     'context_processors': [
                         'django.template.context_processors.request',
                         'context.processor.2',
                     ],
                 },
             },
         ],
     )
 def test_new_setting(self):
     '''
     A new setting (i.e. not in the DJANGO_SETTINGS_MODULE)
     should just end up as the new value.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_new_setting']
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['NEW_LIST_SETTING'], [1, 2, 3])
    def test_list_merging(self):
        '''
        Test that list settings are merged correctly
        '''

        self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_list']
        autoconfig.configure_settings(self.settings_dict)
        self.assertEqual(self.settings_dict['LIST_SETTING'], [1, 2, 3])
 def test_importerror_from_import_error(self):
     '''
     An import error due to the module itself generating an import error should be raised.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_broken_autoconfig']
     with self.assertRaises(ImportError) as exception_manager:
         autoconfig.configure_settings(self.settings_dict)
     self.assertIn('flibble', str(exception_manager.exception))
Пример #16
0
 def test_blank_autoconfig(self):
     '''
     An app with a blank autoconfig shouldn't break things.
     '''
     self.settings_dict['INSTALLED_APPS'] = [
         'django_autoconfig.tests.app_blank_autoconfig'
     ]
     autoconfig.configure_settings(self.settings_dict)
Пример #17
0
 def test_disabled_autoconfig(self):
     '''
     Test the ability to disable autoconfig for some apps.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_list']
     self.settings_dict['AUTOCONFIG_DISABLED_APPS'] = ['django_autoconfig.tests.app_list']
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['LIST_SETTING'], [1, 2])
Пример #18
0
 def test_importerror_from_import_error(self):
     '''
     An import error due to the module itself generating an import error should be raised.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_broken_autoconfig']
     with self.assertRaises(ImportError) as exception_manager:
         autoconfig.configure_settings(self.settings_dict)
     self.assertIn('flibble', str(exception_manager.exception))
Пример #19
0
 def test_new_setting(self):
     '''
     A new setting (i.e. not in the DJANGO_SETTINGS_MODULE)
     should just end up as the new value.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_new_setting']
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['NEW_LIST_SETTING'], [1, 2, 3])
Пример #20
0
    def test_list_merging(self):
        '''
        Test that list settings are merged correctly
        '''

        self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_list']
        autoconfig.configure_settings(self.settings_dict)
        self.assertEqual(self.settings_dict['LIST_SETTING'], [1, 2, 3])
Пример #21
0
 def test_default_existing_setting(self):
     '''
     A setting in the DEFAULTS section should only be used if
     it doesn't already exist.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_default_settings']
     self.settings_dict['DEFAULT_SETTING'] = [4, 5, 6]
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['DEFAULT_SETTING'], [4, 5, 6])
Пример #22
0
 def test_list_setting_from_defaults(self):
     '''
     A list setting that exists in the django.conf.settings.global_settings
     should merge with the default, not replace it entirely.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_middleware']
     autoconfig.configure_settings(self.settings_dict)
     self.assertIn('my.middleware', self.settings_dict['MIDDLEWARE_CLASSES'])
     self.assertIn('django.middleware.common.CommonMiddleware', self.settings_dict['MIDDLEWARE_CLASSES'])
Пример #23
0
 def test_list_setting_from_defaults(self):
     '''
     A list setting that exists in the django.conf.settings.global_settings
     should merge with the default, not replace it entirely.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_middleware']
     autoconfig.configure_settings(self.settings_dict)
     self.assertIn('my.middleware', self.settings_dict['MIDDLEWARE_CLASSES'])
     self.assertIn('django.middleware.common.CommonMiddleware', self.settings_dict['MIDDLEWARE_CLASSES'])
 def test_default_existing_setting(self):
     '''
     A setting in the DEFAULTS section should only be used if
     it doesn't already exist.
     '''
     self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_default_settings']
     self.settings_dict['DEFAULT_SETTING'] = [4, 5, 6]
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(self.settings_dict['DEFAULT_SETTING'], [4, 5, 6])
 def test_no_autoconfig(self):
     '''
     An app with no autoconfig shouldn't break things.
     '''
     self.settings_dict['INSTALLED_APPS'] = [
         'django_autoconfig.tests.app_no_autoconfig',
         'django',
     ]
     autoconfig.configure_settings(self.settings_dict)
Пример #26
0
    def test_contrib_admin(self):
        '''
        Test that our django.contrib.admin dependencies work.
        '''
        settings_dict = {
            'INSTALLED_APPS': [
                'django_autoconfig.tests.app_contrib_admin',
            ],
        }

        autoconfig.configure_settings(settings_dict)
        with test.utils.override_settings(**settings_dict):
            self.create_urlconf(
                list(settings_dict['INSTALLED_APPS']) + list(settings_dict['AUTOCONFIG_EXTRA_URLS']),
            )
            resolve('/django-autoconfig.contrib.admin/', urlconf=self)
    def test_contrib_admin(self):
        '''
        Test that our django.contrib.admin dependencies work.
        '''
        settings_dict = {
            'INSTALLED_APPS': [
                'django_autoconfig.tests.app_contrib_admin',
            ],
        }

        autoconfig.configure_settings(settings_dict)
        with test.utils.override_settings(**settings_dict):
            self.create_urlconf(
                list(settings_dict['INSTALLED_APPS']) + list(settings_dict['AUTOCONFIG_EXTRA_URLS']),
            )
            resolve('/django-autoconfig.contrib.admin/', urlconf=self)
Пример #28
0
 def test_relationship(self):
     '''
     Test putting things somewhere other than at the end of the list.
     '''
     self.settings_dict['INSTALLED_APPS'] = [
         'django_autoconfig.tests.app1',
         'django_autoconfig.tests.app2',
         'django_autoconfig.tests.app_relationship',
     ]
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(
         self.settings_dict['INSTALLED_APPS'],
         [
             'django_autoconfig.tests.app_relationship',
             'django_autoconfig.tests.app1',
             'django_autoconfig.tests.app3',
             'django_autoconfig.tests.app2',
         ],
     )
 def test_relationship(self):
     '''
     Test putting things somewhere other than at the end of the list.
     '''
     self.settings_dict['INSTALLED_APPS'] = [
         'django_autoconfig.tests.app1',
         'django_autoconfig.tests.app2',
         'django_autoconfig.tests.app_relationship',
     ]
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(
         self.settings_dict['INSTALLED_APPS'],
         [
             'django_autoconfig.tests.app_relationship',
             'django_autoconfig.tests.app1',
             'django_autoconfig.tests.app3',
             'django_autoconfig.tests.app2',
         ],
     )
    def test_list_setting_from_defaults_django_2_x(self):
        '''
        A list setting that exists in the django.conf.settings.global_settings
        should merge with the default, not replace it entirely.

        Since Django 2.0, MIDDLEWARE_CLASSES is removed and MIDDLEWARE has empty default.
        Simulate non-empty default by replacing the global default value.
        '''
        from django.conf import global_settings

        # Overwrite the default settings.
        old_middleware = global_settings.MIDDLEWARE
        global_settings.MIDDLEWARE = ['django.middleware.common.CommonMiddleware']

        try:
            self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_middleware']
            autoconfig.configure_settings(self.settings_dict)
            self.assertIn('my.middleware', self.settings_dict['MIDDLEWARE'])
            self.assertIn('django.middleware.common.CommonMiddleware', self.settings_dict['MIDDLEWARE'])
        finally:
            # Restore default settings to its original value.
            global_settings.MIDDLEWARE = old_middleware
 def test_django18_templates(self):
     '''
     Check that the Django 1.8 TEMPLATES setting works.
     '''
     self.settings_dict['INSTALLED_APPS'] = [
         'django_autoconfig.tests.app_18templates1',
         'django_autoconfig.tests.app_18templates2',
     ]
     autoconfig.configure_settings(self.settings_dict)
     self.assertEqual(
         self.settings_dict['TEMPLATES'],
         [
             {
                 'BACKEND': 'django.template.backends.django.DjangoTemplates',
                 'APP_DIRS': True,
                 'OPTIONS': {
                     'context_processors': [
                         'django.template.context_processors.request',
                         'context.processor.2',
                     ],
                 },
             },
         ],
     )
Пример #32
0
}

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

USE_I18N = True
USE_L10N = True

TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-gb'
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static')
STATIC_URL = '/static/'
SECRET_KEY = 'not-a-secret'

ROOT_URLCONF = 'django_autoconfig.autourlconf'

WSGI_APPLICATION = 'example_project.wsgi.application'

INSTALLED_APPS = (
    'game',
)

PIPELINE_ENABLED = False

try:
    from example_project.local_settings import * # pylint: disable=E0611
except ImportError:
    pass

from django_autoconfig import autoconfig
autoconfig.configure_settings(globals())
Пример #33
0
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

USE_I18N = True
USE_L10N = True

TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-gb'
LANGUAGES = (('en-gb', 'English'),)
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static')
STATIC_URL = '/static/'
SECRET_KEY = 'not-a-secret'

ROOT_URLCONF = 'django_autoconfig.autourlconf'

WSGI_APPLICATION = 'example_project.wsgi.application'

INSTALLED_APPS = (
    'game',
)

PIPELINE_ENABLED = False

try:
    from example_project.local_settings import * # pylint: disable=E0611
except ImportError:
    pass

from django_autoconfig import autoconfig
autoconfig.configure_settings(globals())
Пример #34
0
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
    },
}

ROOT_URLCONF = 'django_autoconfig.autourlconf'
INSTALLED_APPS = ['shorty',]
STATIC_URL = '/static/'
STATIC_ROOT = ''

from django_autoconfig.autoconfig import configure_settings
configure_settings(globals())