Skip to content

Commit

Permalink
Move tests to the django model.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebryant committed Mar 4, 2014
1 parent e3795af commit 48f14be
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 99 deletions.
File renamed without changes.
92 changes: 92 additions & 0 deletions django_autoconfig/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'''Tests for django-autoconfig.'''
# pylint: disable=C0103
# pylint: disable=R0904

from django_autoconfig import autoconfig

import copy
from django.core.exceptions import ImproperlyConfigured
from django import test

class ConfigureSettingsTestCase(test.TestCase):
'''Test the configure_settings method.'''

BASE_SETTINGS = {
'LIST_SETTING': [1, 2],
'BOOLEAN_SETTING': True,
'DICT_SETTING': {
'key1': 'value1',
},
}

def setUp(self):
self.settings_dict = copy.deepcopy(self.BASE_SETTINGS)

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_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_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_no_autoconfig(self):
'''
An app with no autoconfig shouldn't break things.
'''
self.settings_dict['INSTALLED_APPS'] = ['django_autoconfig.tests.app_no_autoconfig']
autoconfig.configure_settings(self.settings_dict)

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)

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)

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_relationship(self):
'''
Test putting things somewhere other than at the end of the list.
'''
self.settings_dict['INSTALLED_APPS'] = ['app1', 'app2', 'django_autoconfig.tests.app_relationship']
autoconfig.configure_settings(self.settings_dict)
self.assertEqual(
self.settings_dict['INSTALLED_APPS'],
['django_autoconfig.tests.app_relationship', 'app1', 'app3', 'app2'],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
RELATIONSHIPS = [
OrderingRelationship(
'INSTALLED_APPS',
'tests.app_relationship',
'django_autoconfig.tests.app_relationship',
before=['app1'],
),
OrderingRelationship(
'INSTALLED_APPS',
'tests.app_relationship',
'django_autoconfig.tests.app_relationship',
before=['app3'],
add_missing=True,
),
OrderingRelationship(
'INSTALLED_APPS',
'tests.app_relationship',
'django_autoconfig.tests.app_relationship',
before=['app4'],
add_missing=False,
),
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
author_email='mike@mikebryant.me.uk',
install_requires=INSTALL_REQUIRES,
include_package_data=True,
test_suite='tests',
test_suite = 'setuptest.setuptest.SetupTestSuite',
tests_require = ['django-setuptest'],
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
Expand Down
7 changes: 7 additions & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
},
}
INSTALLED_APPS = ['django_autoconfig']
ROOT_URLCONF = 'django_autoconfig.autourlconf'
95 changes: 0 additions & 95 deletions tests/__init__.py

This file was deleted.

0 comments on commit 48f14be

Please sign in to comment.