mirror of
https://github.com/jazzband/django-configurations.git
synced 2026-03-16 22:20:27 +00:00
Moved tests out of the configurations packages.
This commit is contained in:
parent
46809d02b2
commit
5898acb594
18 changed files with 66 additions and 64 deletions
|
|
@ -6,7 +6,7 @@ python:
|
||||||
- 3.3
|
- 3.3
|
||||||
install:
|
install:
|
||||||
- pip install -e .
|
- pip install -e .
|
||||||
- pip install -r requirements/tests.txt
|
- pip install -r tests/requirements.txt
|
||||||
- pip install https://github.com/django/django/archive/${DJANGO}.zip#egg=django
|
- pip install https://github.com/django/django/archive/${DJANGO}.zip#egg=django
|
||||||
script:
|
script:
|
||||||
- inv test
|
- inv test
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
include README.rst
|
include README.rst
|
||||||
include CHANGES.rst
|
include CHANGES.rst
|
||||||
|
include AUTHORS
|
||||||
include .travis.yml
|
include .travis.yml
|
||||||
include manage.py
|
include manage.py
|
||||||
include tasks.py
|
include tasks.py
|
||||||
include requirements/tests.txt
|
recursive-include tests *
|
||||||
recursive-include docs *
|
recursive-include docs *
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
from .base import Settings, Configuration
|
from .base import Settings, Configuration
|
||||||
from .decorators import pristinemethod
|
from .decorators import pristinemethod
|
||||||
|
|
||||||
__version__ = '0.4'
|
__version__ = '0.5'
|
||||||
__all__ = ['Configuration', 'pristinemethod', 'Settings']
|
__all__ = ['Configuration', 'pristinemethod', 'Settings']
|
||||||
|
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
import os
|
|
||||||
|
|
||||||
from django.conf import global_settings
|
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
from mock import patch
|
|
||||||
|
|
||||||
|
|
||||||
class InheritanceTests(TestCase):
|
|
||||||
|
|
||||||
@patch.dict(os.environ, clear=True,
|
|
||||||
DJANGO_CONFIGURATION='Inheritance',
|
|
||||||
DJANGO_SETTINGS_MODULE='configurations.tests.settings.single_inheritance')
|
|
||||||
def test_inherited(self):
|
|
||||||
from configurations.tests.settings import single_inheritance
|
|
||||||
self.assertEqual(single_inheritance.TEMPLATE_CONTEXT_PROCESSORS,
|
|
||||||
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
|
||||||
'configurations.tests.settings.base.test_callback',
|
|
||||||
))
|
|
||||||
|
|
||||||
@patch.dict(os.environ, clear=True,
|
|
||||||
DJANGO_CONFIGURATION='Inheritance',
|
|
||||||
DJANGO_SETTINGS_MODULE='configurations.tests.settings.multiple_inheritance')
|
|
||||||
def test_inherited2(self):
|
|
||||||
from configurations.tests.settings import multiple_inheritance
|
|
||||||
self.assertEqual(multiple_inheritance.TEMPLATE_CONTEXT_PROCESSORS,
|
|
||||||
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
|
||||||
'configurations.tests.settings.base.test_callback',
|
|
||||||
'configurations.tests.settings.base.test_callback',
|
|
||||||
))
|
|
||||||
|
|
||||||
@patch.dict(os.environ, clear=True,
|
|
||||||
DJANGO_CONFIGURATION='Inheritance',
|
|
||||||
DJANGO_SETTINGS_MODULE='configurations.tests.settings.mixin_inheritance')
|
|
||||||
def test_inherited3(self):
|
|
||||||
from configurations.tests.settings import mixin_inheritance
|
|
||||||
self.assertEqual(mixin_inheritance.TEMPLATE_CONTEXT_PROCESSORS,
|
|
||||||
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
|
||||||
'some_app.context_processors.processor1',
|
|
||||||
'some_app.context_processors.processor2',
|
|
||||||
'some_app.context_processors.processorbase',
|
|
||||||
))
|
|
||||||
|
|
@ -3,8 +3,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings.main')
|
||||||
'configurations.tests.settings.main')
|
|
||||||
os.environ.setdefault('DJANGO_CONFIGURATION', 'Test')
|
os.environ.setdefault('DJANGO_CONFIGURATION', 'Test')
|
||||||
|
|
||||||
from configurations.management import execute_from_command_line
|
from configurations.management import execute_from_command_line
|
||||||
|
|
|
||||||
2
tasks.py
2
tasks.py
|
|
@ -2,7 +2,7 @@ from invoke import run, task
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def test(label='configurations'):
|
def test(label='tests'):
|
||||||
run('flake8 configurations --ignore=E501,E127,E128,E124')
|
run('flake8 configurations --ignore=E501,E127,E128,E124')
|
||||||
run('./manage.py test {0} -v2'.format(label))
|
run('./manage.py test {0} -v2'.format(label))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,18 @@ class Test(Configuration):
|
||||||
'django.contrib.sites',
|
'django.contrib.sites',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'configurations.tests',
|
'tests',
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'configurations.tests.urls'
|
ROOT_URLCONF = 'tests.urls'
|
||||||
|
|
||||||
if django.VERSION[:2] < (1, 6):
|
if django.VERSION[:2] < (1, 6):
|
||||||
TEST_RUNNER = 'discover_runner.DiscoverRunner'
|
TEST_RUNNER = 'discover_runner.DiscoverRunner'
|
||||||
|
|
||||||
def TEMPLATE_CONTEXT_PROCESSORS(self):
|
def TEMPLATE_CONTEXT_PROCESSORS(self):
|
||||||
return Configuration.TEMPLATE_CONTEXT_PROCESSORS + (
|
return Configuration.TEMPLATE_CONTEXT_PROCESSORS + (
|
||||||
'configurations.tests.settings.base.test_callback',)
|
'tests.settings.base.test_callback',
|
||||||
|
)
|
||||||
|
|
||||||
ATTRIBUTE_SETTING = True
|
ATTRIBUTE_SETTING = True
|
||||||
|
|
||||||
|
|
@ -5,4 +5,4 @@ class Inheritance(Test):
|
||||||
|
|
||||||
def TEMPLATE_CONTEXT_PROCESSORS(self):
|
def TEMPLATE_CONTEXT_PROCESSORS(self):
|
||||||
return super(Inheritance, self).TEMPLATE_CONTEXT_PROCESSORS() + (
|
return super(Inheritance, self).TEMPLATE_CONTEXT_PROCESSORS() + (
|
||||||
'configurations.tests.settings.base.test_callback',)
|
'tests.settings.base.test_callback',)
|
||||||
|
|
@ -5,4 +5,4 @@ class Inheritance(Base):
|
||||||
|
|
||||||
def TEMPLATE_CONTEXT_PROCESSORS(self):
|
def TEMPLATE_CONTEXT_PROCESSORS(self):
|
||||||
return super(Inheritance, self).TEMPLATE_CONTEXT_PROCESSORS + (
|
return super(Inheritance, self).TEMPLATE_CONTEXT_PROCESSORS + (
|
||||||
'configurations.tests.settings.base.test_callback',)
|
'tests.settings.base.test_callback',)
|
||||||
42
tests/test_inheritance.py
Normal file
42
tests/test_inheritance.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.conf import global_settings
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from mock import patch
|
||||||
|
|
||||||
|
|
||||||
|
class InheritanceTests(TestCase):
|
||||||
|
|
||||||
|
@patch.dict(os.environ, clear=True,
|
||||||
|
DJANGO_CONFIGURATION='Inheritance',
|
||||||
|
DJANGO_SETTINGS_MODULE='tests.settings.single_inheritance')
|
||||||
|
def test_inherited(self):
|
||||||
|
from tests.settings import single_inheritance
|
||||||
|
self.assertEqual(single_inheritance.TEMPLATE_CONTEXT_PROCESSORS,
|
||||||
|
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
||||||
|
'tests.settings.base.test_callback',
|
||||||
|
))
|
||||||
|
|
||||||
|
@patch.dict(os.environ, clear=True,
|
||||||
|
DJANGO_CONFIGURATION='Inheritance',
|
||||||
|
DJANGO_SETTINGS_MODULE='tests.settings.multiple_inheritance')
|
||||||
|
def test_inherited2(self):
|
||||||
|
from tests.settings import multiple_inheritance
|
||||||
|
self.assertEqual(multiple_inheritance.TEMPLATE_CONTEXT_PROCESSORS,
|
||||||
|
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
||||||
|
'tests.settings.base.test_callback',
|
||||||
|
'tests.settings.base.test_callback',
|
||||||
|
))
|
||||||
|
|
||||||
|
@patch.dict(os.environ, clear=True,
|
||||||
|
DJANGO_CONFIGURATION='Inheritance',
|
||||||
|
DJANGO_SETTINGS_MODULE='tests.settings.mixin_inheritance')
|
||||||
|
def test_inherited3(self):
|
||||||
|
from tests.settings import mixin_inheritance
|
||||||
|
self.assertEqual(mixin_inheritance.TEMPLATE_CONTEXT_PROCESSORS,
|
||||||
|
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
||||||
|
'some_app.context_processors.processor1',
|
||||||
|
'some_app.context_processors.processor2',
|
||||||
|
'some_app.context_processors.processorbase',
|
||||||
|
))
|
||||||
|
|
@ -12,7 +12,7 @@ from configurations.importer import ConfigurationImporter
|
||||||
class MainTests(TestCase):
|
class MainTests(TestCase):
|
||||||
|
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
from configurations.tests.settings import main
|
from tests.settings import main
|
||||||
self.assertEqual(main.ATTRIBUTE_SETTING, True)
|
self.assertEqual(main.ATTRIBUTE_SETTING, True)
|
||||||
self.assertEqual(main.PROPERTY_SETTING, 1)
|
self.assertEqual(main.PROPERTY_SETTING, 1)
|
||||||
self.assertEqual(main.METHOD_SETTING, 2)
|
self.assertEqual(main.METHOD_SETTING, 2)
|
||||||
|
|
@ -23,7 +23,7 @@ class MainTests(TestCase):
|
||||||
self.assertTrue(lambda: callable(main.PRISTINE_FUNCTION_SETTING))
|
self.assertTrue(lambda: callable(main.PRISTINE_FUNCTION_SETTING))
|
||||||
self.assertEqual(main.TEMPLATE_CONTEXT_PROCESSORS,
|
self.assertEqual(main.TEMPLATE_CONTEXT_PROCESSORS,
|
||||||
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
|
||||||
'configurations.tests.settings.base.test_callback',
|
'tests.settings.base.test_callback',
|
||||||
))
|
))
|
||||||
self.assertEqual(main.PRE_SETUP_TEST_SETTING, 6)
|
self.assertEqual(main.PRE_SETUP_TEST_SETTING, 6)
|
||||||
self.assertRaises(AttributeError, lambda: main.POST_SETUP_TEST_SETTING)
|
self.assertRaises(AttributeError, lambda: main.POST_SETUP_TEST_SETTING)
|
||||||
|
|
@ -44,36 +44,37 @@ class MainTests(TestCase):
|
||||||
self.assertRaises(ImproperlyConfigured, ConfigurationImporter)
|
self.assertRaises(ImproperlyConfigured, ConfigurationImporter)
|
||||||
|
|
||||||
@patch.dict(os.environ, clear=True,
|
@patch.dict(os.environ, clear=True,
|
||||||
DJANGO_SETTINGS_MODULE='configurations.tests.settings.main')
|
DJANGO_SETTINGS_MODULE='tests.settings.main')
|
||||||
def test_empty_class_var(self):
|
def test_empty_class_var(self):
|
||||||
self.assertRaises(ImproperlyConfigured, ConfigurationImporter)
|
self.assertRaises(ImproperlyConfigured, ConfigurationImporter)
|
||||||
|
|
||||||
def test_global_settings(self):
|
def test_global_settings(self):
|
||||||
from configurations.base import Configuration
|
from configurations.base import Configuration
|
||||||
self.assertEqual(Configuration.LOGGING_CONFIG, 'django.utils.log.dictConfig')
|
self.assertEqual(Configuration.LOGGING_CONFIG,
|
||||||
|
'django.utils.log.dictConfig')
|
||||||
self.assertEqual(repr(Configuration),
|
self.assertEqual(repr(Configuration),
|
||||||
"<Configuration 'configurations.base.Configuration'>")
|
"<Configuration 'configurations.base.Configuration'>")
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
from configurations.tests.settings.main import Test
|
from tests.settings.main import Test
|
||||||
self.assertEqual(repr(Test),
|
self.assertEqual(repr(Test),
|
||||||
"<Configuration 'configurations.tests.settings.main.Test'>")
|
"<Configuration 'tests.settings.main.Test'>")
|
||||||
|
|
||||||
@patch.dict(os.environ, clear=True,
|
@patch.dict(os.environ, clear=True,
|
||||||
DJANGO_SETTINGS_MODULE='configurations.tests.settings.main',
|
DJANGO_SETTINGS_MODULE='tests.settings.main',
|
||||||
DJANGO_CONFIGURATION='Test')
|
DJANGO_CONFIGURATION='Test')
|
||||||
def test_initialization(self):
|
def test_initialization(self):
|
||||||
importer = ConfigurationImporter()
|
importer = ConfigurationImporter()
|
||||||
self.assertEqual(importer.module, 'configurations.tests.settings.main')
|
self.assertEqual(importer.module, 'tests.settings.main')
|
||||||
self.assertEqual(importer.name, 'Test')
|
self.assertEqual(importer.name, 'Test')
|
||||||
self.assertEqual(repr(importer),
|
self.assertEqual(repr(importer),
|
||||||
"<ConfigurationImporter for 'configurations.tests.settings.main.Test'>")
|
"<ConfigurationImporter for 'tests.settings.main.Test'>")
|
||||||
|
|
||||||
@patch.dict(os.environ, clear=True,
|
@patch.dict(os.environ, clear=True,
|
||||||
DJANGO_SETTINGS_MODULE='configurations.tests.settings.inheritance',
|
DJANGO_SETTINGS_MODULE='tests.settings.inheritance',
|
||||||
DJANGO_CONFIGURATION='Inheritance')
|
DJANGO_CONFIGURATION='Inheritance')
|
||||||
def test_initialization_inheritance(self):
|
def test_initialization_inheritance(self):
|
||||||
importer = ConfigurationImporter()
|
importer = ConfigurationImporter()
|
||||||
self.assertEqual(importer.module,
|
self.assertEqual(importer.module,
|
||||||
'configurations.tests.settings.inheritance')
|
'tests.settings.inheritance')
|
||||||
self.assertEqual(importer.name, 'Inheritance')
|
self.assertEqual(importer.name, 'Inheritance')
|
||||||
Loading…
Reference in a new issue