Moved tests into a new appconf package. Shouldn't have any different behavior.
This commit is contained in:
5
appconf/__init__.py
Normal file
5
appconf/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
from .base import AppConf # noqa
|
||||
|
||||
# following PEP 386, versiontools will pick it up
|
||||
__version__ = (0, 4, 1, "final", 0)
|
||||
@@ -1,7 +1,5 @@
|
||||
import sys
|
||||
|
||||
# following PEP 386, versiontools will pick it up
|
||||
__version__ = (0, 4, 1, "final", 0)
|
||||
from .utils import import_attribute
|
||||
|
||||
|
||||
class AppConfOptions(object):
|
||||
@@ -56,7 +54,8 @@ class AppConfMetaClass(type):
|
||||
if hasattr(parent, '_meta'):
|
||||
new_class._meta.names.update(parent._meta.names)
|
||||
new_class._meta.defaults.update(parent._meta.defaults)
|
||||
new_class._meta.configured_data.update(parent._meta.configured_data)
|
||||
new_class._meta.configured_data.update(
|
||||
parent._meta.configured_data)
|
||||
|
||||
for name in filter(lambda name: name == name.upper(), attrs):
|
||||
prefixed_name = new_class._meta.prefixed_name(name)
|
||||
@@ -93,27 +92,6 @@ class AppConfMetaClass(type):
|
||||
cls._meta.configured_data = obj.configure()
|
||||
|
||||
|
||||
def import_attribute(import_path, exception_handler=None):
|
||||
from django.utils.importlib import import_module
|
||||
module_name, object_name = import_path.rsplit('.', 1)
|
||||
try:
|
||||
module = import_module(module_name)
|
||||
except: # pragma: no cover
|
||||
if callable(exception_handler):
|
||||
exctype, excvalue, tb = sys.exc_info()
|
||||
return exception_handler(import_path, exctype, excvalue, tb)
|
||||
else:
|
||||
raise
|
||||
try:
|
||||
return getattr(module, object_name)
|
||||
except: # pragma: no cover
|
||||
if callable(exception_handler):
|
||||
exctype, excvalue, tb = sys.exc_info()
|
||||
return exception_handler(import_path, exctype, excvalue, tb)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
class AppConf(object):
|
||||
"""
|
||||
An app setting object to be used for handling app setting defaults
|
||||
@@ -13,7 +13,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.auth',
|
||||
'django.contrib.admin',
|
||||
'django_jenkins',
|
||||
'tests.testapp',
|
||||
'appconf.tests',
|
||||
]
|
||||
|
||||
JENKINS_TASKS = (
|
||||
@@ -61,5 +61,5 @@ class CustomHolderConf(AppConf):
|
||||
SIMPLE_VALUE = True
|
||||
|
||||
class Meta:
|
||||
holder = 'tests.testapp.models.custom_holder' # instead of django.conf.settings
|
||||
holder = 'appconf.tests.models.custom_holder' # instead of django.conf.settings
|
||||
prefix = 'custom_holder'
|
||||
@@ -10,50 +10,50 @@ from .models import (TestConf, PrefixConf, YetAnotherPrefixConf,
|
||||
class TestConfTests(TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
self.assertEquals(TestConf._meta.prefix, 'testapp')
|
||||
self.assertEquals(TestConf._meta.prefix, 'tests')
|
||||
|
||||
def test_simple(self):
|
||||
self.assertTrue(hasattr(settings, 'TESTAPP_SIMPLE_VALUE'))
|
||||
self.assertEquals(settings.TESTAPP_SIMPLE_VALUE, True)
|
||||
self.assertTrue(hasattr(settings, 'TESTS_SIMPLE_VALUE'))
|
||||
self.assertEquals(settings.TESTS_SIMPLE_VALUE, True)
|
||||
|
||||
def test_configured(self):
|
||||
self.assertTrue(hasattr(settings, 'TESTAPP_CONFIGURED_VALUE'))
|
||||
self.assertEquals(settings.TESTAPP_CONFIGURED_VALUE, 'correct')
|
||||
self.assertTrue(hasattr(settings, 'TESTS_CONFIGURED_VALUE'))
|
||||
self.assertEquals(settings.TESTS_CONFIGURED_VALUE, 'correct')
|
||||
|
||||
def test_configure_method(self):
|
||||
self.assertTrue(hasattr(settings, 'TESTAPP_CONFIGURE_METHOD_VALUE'))
|
||||
self.assertEquals(settings.TESTAPP_CONFIGURE_METHOD_VALUE, True)
|
||||
self.assertTrue(hasattr(settings, 'TESTS_CONFIGURE_METHOD_VALUE'))
|
||||
self.assertEquals(settings.TESTS_CONFIGURE_METHOD_VALUE, True)
|
||||
|
||||
def test_init_kwargs(self):
|
||||
custom_conf = TestConf(CUSTOM_VALUE='custom')
|
||||
self.assertEquals(custom_conf.CUSTOM_VALUE, 'custom')
|
||||
self.assertEquals(settings.TESTAPP_CUSTOM_VALUE, 'custom')
|
||||
self.assertRaises(AttributeError, lambda: custom_conf.TESTAPP_CUSTOM_VALUE)
|
||||
self.assertEquals(settings.TESTS_CUSTOM_VALUE, 'custom')
|
||||
self.assertRaises(AttributeError, lambda: custom_conf.TESTS_CUSTOM_VALUE)
|
||||
custom_conf.CUSTOM_VALUE_SETATTR = 'custom'
|
||||
self.assertEquals(settings.TESTAPP_CUSTOM_VALUE_SETATTR, 'custom')
|
||||
self.assertEquals(settings.TESTS_CUSTOM_VALUE_SETATTR, 'custom')
|
||||
custom_conf.custom_value_lowercase = 'custom'
|
||||
self.assertRaises(AttributeError, lambda: settings.custom_value_lowercase)
|
||||
|
||||
def test_init_kwargs_with_prefix(self):
|
||||
custom_conf = TestConf(TESTAPP_CUSTOM_VALUE2='custom2')
|
||||
self.assertEquals(custom_conf.TESTAPP_CUSTOM_VALUE2, 'custom2')
|
||||
self.assertEquals(settings.TESTAPP_CUSTOM_VALUE2, 'custom2')
|
||||
custom_conf = TestConf(TESTS_CUSTOM_VALUE2='custom2')
|
||||
self.assertEquals(custom_conf.TESTS_CUSTOM_VALUE2, 'custom2')
|
||||
self.assertEquals(settings.TESTS_CUSTOM_VALUE2, 'custom2')
|
||||
|
||||
def test_proxy(self):
|
||||
custom_conf = ProxyConf(CUSTOM_VALUE3='custom3')
|
||||
self.assertEquals(custom_conf.CUSTOM_VALUE3, 'custom3')
|
||||
self.assertEquals(settings.TESTAPP_CUSTOM_VALUE3, 'custom3')
|
||||
self.assertEquals(custom_conf.TESTAPP_CUSTOM_VALUE3, 'custom3')
|
||||
self.assertTrue('tests.testapp' in custom_conf.INSTALLED_APPS)
|
||||
self.assertEquals(settings.TESTS_CUSTOM_VALUE3, 'custom3')
|
||||
self.assertEquals(custom_conf.TESTS_CUSTOM_VALUE3, 'custom3')
|
||||
self.assertTrue('appconf.tests' in custom_conf.INSTALLED_APPS)
|
||||
|
||||
def test_dir_members(self):
|
||||
custom_conf = TestConf()
|
||||
self.assertTrue('TESTAPP_SIMPLE_VALUE' in dir(settings))
|
||||
self.assertTrue('TESTAPP_SIMPLE_VALUE' in settings.__members__)
|
||||
self.assertTrue('TESTS_SIMPLE_VALUE' in dir(settings))
|
||||
self.assertTrue('TESTS_SIMPLE_VALUE' in settings.__members__)
|
||||
self.assertTrue('SIMPLE_VALUE' in dir(custom_conf))
|
||||
self.assertTrue('SIMPLE_VALUE' in custom_conf.__members__)
|
||||
self.assertFalse('TESTAPP_SIMPLE_VALUE' in dir(custom_conf))
|
||||
self.assertFalse('TESTAPP_SIMPLE_VALUE' in custom_conf.__members__)
|
||||
self.assertFalse('TESTS_SIMPLE_VALUE' in dir(custom_conf))
|
||||
self.assertFalse('TESTS_SIMPLE_VALUE' in custom_conf.__members__)
|
||||
|
||||
def test_custom_holder(self):
|
||||
custom_conf = CustomHolderConf()
|
||||
@@ -61,8 +61,8 @@ class TestConfTests(TestCase):
|
||||
self.assertEquals(custom_holder.CUSTOM_HOLDER_SIMPLE_VALUE, True)
|
||||
|
||||
def test_subclass_configured_data(self):
|
||||
self.assertTrue('TESTAPP_CONFIGURE_METHOD_VALUE2' in dir(settings))
|
||||
self.assertEquals(settings.TESTAPP_CONFIGURE_METHOD_VALUE2, False)
|
||||
self.assertTrue('TESTS_CONFIGURE_METHOD_VALUE2' in dir(settings))
|
||||
self.assertEquals(settings.TESTS_CONFIGURE_METHOD_VALUE2, False)
|
||||
|
||||
|
||||
class PrefixConfTests(TestCase):
|
||||
22
appconf/utils.py
Normal file
22
appconf/utils.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import sys
|
||||
|
||||
|
||||
def import_attribute(import_path, exception_handler=None):
|
||||
from django.utils.importlib import import_module
|
||||
module_name, object_name = import_path.rsplit('.', 1)
|
||||
try:
|
||||
module = import_module(module_name)
|
||||
except: # pragma: no cover
|
||||
if callable(exception_handler):
|
||||
exctype, excvalue, tb = sys.exc_info()
|
||||
return exception_handler(import_path, exctype, excvalue, tb)
|
||||
else:
|
||||
raise
|
||||
try:
|
||||
return getattr(module, object_name)
|
||||
except: # pragma: no cover
|
||||
if callable(exception_handler):
|
||||
exctype, excvalue, tb = sys.exc_info()
|
||||
return exception_handler(import_path, exctype, excvalue, tb)
|
||||
else:
|
||||
raise
|
||||
5
setup.py
5
setup.py
@@ -14,7 +14,10 @@ setup(
|
||||
author_email='jannis@leidel.info',
|
||||
license = 'BSD',
|
||||
url='http://django-appconf.readthedocs.org/',
|
||||
py_modules=['appconf'],
|
||||
packages=[
|
||||
'appconf',
|
||||
'appconf.tests',
|
||||
],
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
'Environment :: Web Environment',
|
||||
|
||||
4
tox.ini
4
tox.ini
@@ -1,9 +1,9 @@
|
||||
[testenv]
|
||||
downloadcache = {toxworkdir}/_download/
|
||||
commands =
|
||||
{envbindir}/python {envbindir}/django-admin.py jenkins {posargs:testapp}
|
||||
{envbindir}/python {envbindir}/django-admin.py jenkins {posargs:tests}
|
||||
setenv =
|
||||
DJANGO_SETTINGS_MODULE = tests.settings
|
||||
DJANGO_SETTINGS_MODULE = appconf.test_settings
|
||||
|
||||
[testenv:docs]
|
||||
basepython = python2.7
|
||||
|
||||
Reference in New Issue
Block a user