Skip to content

Commit

Permalink
Moved tests into a new appconf package. Shouldn't have any different …
Browse files Browse the repository at this point in the history
…behavior.
  • Loading branch information
jezdez committed Jan 26, 2012
1 parent 4b733b3 commit 1265e18
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 52 deletions.
5 changes: 5 additions & 0 deletions appconf/__init__.py
@@ -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)
28 changes: 3 additions & 25 deletions appconf.py → appconf/base.py
@@ -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):
Expand Down Expand Up @@ -56,7 +54,8 @@ def __new__(cls, name, bases, attrs):
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)
Expand Down Expand Up @@ -93,27 +92,6 @@ def _configure(cls):
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
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py → appconf/test_settings.py
Expand Up @@ -13,7 +13,7 @@
'django.contrib.auth',
'django.contrib.admin',
'django_jenkins',
'tests.testapp',
'appconf.tests',
]

JENKINS_TASKS = (
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/testapp/models.py → appconf/tests/models.py
Expand Up @@ -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'
File renamed without changes.
44 changes: 22 additions & 22 deletions tests/testapp/tests.py → appconf/tests/tests.py
Expand Up @@ -10,59 +10,59 @@
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()
self.assertTrue(hasattr(custom_holder, 'CUSTOM_HOLDER_SIMPLE_VALUE'))
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):
Expand Down
22 changes: 22 additions & 0 deletions appconf/utils.py
@@ -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 changes: 4 additions & 1 deletion setup.py
Expand Up @@ -14,7 +14,10 @@
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',
Expand Down
Empty file removed tests/testapp/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions 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
Expand Down

0 comments on commit 1265e18

Please sign in to comment.