From 48f14be3d5d13e81e7123ace6baf92c281a6e6ec Mon Sep 17 00:00:00 2001 From: Mike Bryant Date: Tue, 4 Mar 2014 01:00:31 +0000 Subject: [PATCH] Move tests to the django model. --- .../models.py | 0 django_autoconfig/tests/__init__.py | 92 ++++++++++++++++++ .../tests/app_blank_autoconfig}/__init__.py | 0 .../tests}/app_blank_autoconfig/autoconfig.py | 0 .../tests/app_boolean}/__init__.py | 0 .../tests}/app_boolean/autoconfig.py | 0 .../app_boolean_inconsistent}/__init__.py | 0 .../app_boolean_inconsistent/autoconfig.py | 0 .../tests/app_list}/__init__.py | 0 .../tests}/app_list/autoconfig.py | 0 .../tests/app_middleware}/__init__.py | 0 .../tests}/app_middleware/autoconfig.py | 0 .../tests/app_new_setting}/__init__.py | 0 .../tests}/app_new_setting/autoconfig.py | 0 .../tests/app_no_autoconfig}/__init__.py | 0 .../tests/app_relationship/__init__.py | 0 .../tests}/app_relationship/autoconfig.py | 6 +- setup.py | 3 +- test_settings.py | 7 ++ tests/__init__.py | 95 ------------------- 20 files changed, 104 insertions(+), 99 deletions(-) rename tests/app_blank_autoconfig/__init__.py => django_autoconfig/models.py (100%) create mode 100644 django_autoconfig/tests/__init__.py rename {tests/app_boolean => django_autoconfig/tests/app_blank_autoconfig}/__init__.py (100%) rename {tests => django_autoconfig/tests}/app_blank_autoconfig/autoconfig.py (100%) rename {tests/app_boolean_inconsistent => django_autoconfig/tests/app_boolean}/__init__.py (100%) rename {tests => django_autoconfig/tests}/app_boolean/autoconfig.py (100%) rename {tests/app_list => django_autoconfig/tests/app_boolean_inconsistent}/__init__.py (100%) rename {tests => django_autoconfig/tests}/app_boolean_inconsistent/autoconfig.py (100%) rename {tests/app_middleware => django_autoconfig/tests/app_list}/__init__.py (100%) rename {tests => django_autoconfig/tests}/app_list/autoconfig.py (100%) rename {tests/app_new_setting => django_autoconfig/tests/app_middleware}/__init__.py (100%) rename {tests => django_autoconfig/tests}/app_middleware/autoconfig.py (100%) rename {tests/app_no_autoconfig => django_autoconfig/tests/app_new_setting}/__init__.py (100%) rename {tests => django_autoconfig/tests}/app_new_setting/autoconfig.py (100%) rename {tests/app_relationship => django_autoconfig/tests/app_no_autoconfig}/__init__.py (100%) create mode 100644 django_autoconfig/tests/app_relationship/__init__.py rename {tests => django_autoconfig/tests}/app_relationship/autoconfig.py (75%) create mode 100644 test_settings.py delete mode 100644 tests/__init__.py diff --git a/tests/app_blank_autoconfig/__init__.py b/django_autoconfig/models.py similarity index 100% rename from tests/app_blank_autoconfig/__init__.py rename to django_autoconfig/models.py diff --git a/django_autoconfig/tests/__init__.py b/django_autoconfig/tests/__init__.py new file mode 100644 index 0000000..94bcaee --- /dev/null +++ b/django_autoconfig/tests/__init__.py @@ -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'], + ) diff --git a/tests/app_boolean/__init__.py b/django_autoconfig/tests/app_blank_autoconfig/__init__.py similarity index 100% rename from tests/app_boolean/__init__.py rename to django_autoconfig/tests/app_blank_autoconfig/__init__.py diff --git a/tests/app_blank_autoconfig/autoconfig.py b/django_autoconfig/tests/app_blank_autoconfig/autoconfig.py similarity index 100% rename from tests/app_blank_autoconfig/autoconfig.py rename to django_autoconfig/tests/app_blank_autoconfig/autoconfig.py diff --git a/tests/app_boolean_inconsistent/__init__.py b/django_autoconfig/tests/app_boolean/__init__.py similarity index 100% rename from tests/app_boolean_inconsistent/__init__.py rename to django_autoconfig/tests/app_boolean/__init__.py diff --git a/tests/app_boolean/autoconfig.py b/django_autoconfig/tests/app_boolean/autoconfig.py similarity index 100% rename from tests/app_boolean/autoconfig.py rename to django_autoconfig/tests/app_boolean/autoconfig.py diff --git a/tests/app_list/__init__.py b/django_autoconfig/tests/app_boolean_inconsistent/__init__.py similarity index 100% rename from tests/app_list/__init__.py rename to django_autoconfig/tests/app_boolean_inconsistent/__init__.py diff --git a/tests/app_boolean_inconsistent/autoconfig.py b/django_autoconfig/tests/app_boolean_inconsistent/autoconfig.py similarity index 100% rename from tests/app_boolean_inconsistent/autoconfig.py rename to django_autoconfig/tests/app_boolean_inconsistent/autoconfig.py diff --git a/tests/app_middleware/__init__.py b/django_autoconfig/tests/app_list/__init__.py similarity index 100% rename from tests/app_middleware/__init__.py rename to django_autoconfig/tests/app_list/__init__.py diff --git a/tests/app_list/autoconfig.py b/django_autoconfig/tests/app_list/autoconfig.py similarity index 100% rename from tests/app_list/autoconfig.py rename to django_autoconfig/tests/app_list/autoconfig.py diff --git a/tests/app_new_setting/__init__.py b/django_autoconfig/tests/app_middleware/__init__.py similarity index 100% rename from tests/app_new_setting/__init__.py rename to django_autoconfig/tests/app_middleware/__init__.py diff --git a/tests/app_middleware/autoconfig.py b/django_autoconfig/tests/app_middleware/autoconfig.py similarity index 100% rename from tests/app_middleware/autoconfig.py rename to django_autoconfig/tests/app_middleware/autoconfig.py diff --git a/tests/app_no_autoconfig/__init__.py b/django_autoconfig/tests/app_new_setting/__init__.py similarity index 100% rename from tests/app_no_autoconfig/__init__.py rename to django_autoconfig/tests/app_new_setting/__init__.py diff --git a/tests/app_new_setting/autoconfig.py b/django_autoconfig/tests/app_new_setting/autoconfig.py similarity index 100% rename from tests/app_new_setting/autoconfig.py rename to django_autoconfig/tests/app_new_setting/autoconfig.py diff --git a/tests/app_relationship/__init__.py b/django_autoconfig/tests/app_no_autoconfig/__init__.py similarity index 100% rename from tests/app_relationship/__init__.py rename to django_autoconfig/tests/app_no_autoconfig/__init__.py diff --git a/django_autoconfig/tests/app_relationship/__init__.py b/django_autoconfig/tests/app_relationship/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/app_relationship/autoconfig.py b/django_autoconfig/tests/app_relationship/autoconfig.py similarity index 75% rename from tests/app_relationship/autoconfig.py rename to django_autoconfig/tests/app_relationship/autoconfig.py index 0417a94..99023a2 100644 --- a/tests/app_relationship/autoconfig.py +++ b/django_autoconfig/tests/app_relationship/autoconfig.py @@ -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, ), diff --git a/setup.py b/setup.py index 9c90cfa..671ac10 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/test_settings.py b/test_settings.py new file mode 100644 index 0000000..91a5ef2 --- /dev/null +++ b/test_settings.py @@ -0,0 +1,7 @@ +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + }, +} +INSTALLED_APPS = ['django_autoconfig'] +ROOT_URLCONF = 'django_autoconfig.autourlconf' diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index f755583..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1,95 +0,0 @@ -'''Tests for django-autoconfig.''' -# pylint: disable=C0103 -# pylint: disable=R0904 - -from django_autoconfig import autoconfig - -import copy -from django.core.exceptions import ImproperlyConfigured -try: - from django.utils import unittest -except ImportError: - import unittest - -class ConfigureSettingsTestCase(unittest.TestCase): - '''Test the configure_settings method.''' - - BASE_SETTINGS = { - 'LIST_SETTING': [1, 2], - 'BOOLEAN_SETTING': True, - 'DICT_SETTING': { - 'key1': 'value1', - }, - } - - def setUp(self): - self.settings = copy.deepcopy(self.BASE_SETTINGS) - - def test_list_merging(self): - ''' - Test that list settings are merged correctly - ''' - - self.settings['INSTALLED_APPS'] = ['tests.app_list'] - autoconfig.configure_settings(self.settings) - self.assertEqual(self.settings['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['INSTALLED_APPS'] = ['tests.app_new_setting'] - autoconfig.configure_settings(self.settings) - self.assertEqual(self.settings['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['INSTALLED_APPS'] = ['tests.app_middleware'] - autoconfig.configure_settings(self.settings) - self.assertIn('my.middleware', self.settings['MIDDLEWARE_CLASSES']) - self.assertIn('django.middleware.common.CommonMiddleware', self.settings['MIDDLEWARE_CLASSES']) - - def test_no_autoconfig(self): - ''' - An app with no autoconfig shouldn't break things. - ''' - self.settings['INSTALLED_APPS'] = ['tests.app_no_autoconfig'] - autoconfig.configure_settings(self.settings) - - def test_blank_autoconfig(self): - ''' - An app with a blank autoconfig shouldn't break things. - ''' - self.settings['INSTALLED_APPS'] = ['tests.app_blank_autoconfig'] - autoconfig.configure_settings(self.settings) - - def test_booleans(self): - ''' - Things we can't merge just get replaced. - ''' - self.settings['INSTALLED_APPS'] = ['tests.app_boolean'] - autoconfig.configure_settings(self.settings) - self.assertEqual(self.settings['DEBUG'], True) - - def test_inconsistency(self): - ''' - Check for required inconsistencies. - ''' - self.settings['INSTALLED_APPS'] = ['tests.app_boolean', 'tests.app_boolean_inconsistent'] - with self.assertRaises(ImproperlyConfigured): - autoconfig.configure_settings(self.settings) - - def test_relationship(self): - ''' - Test putting things somewhere other than at the end of the list. - ''' - self.settings['INSTALLED_APPS'] = ['app1', 'app2', 'tests.app_relationship'] - autoconfig.configure_settings(self.settings) - self.assertEqual( - self.settings['INSTALLED_APPS'], - ['tests.app_relationship', 'app1', 'app3', 'app2'], - )