3 # This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
7 Creates a simple Django configuration and runs tests for fnpdjango.
9 from __future__ import unicode_literals
13 from os.path import dirname, abspath
14 from optparse import OptionParser
15 from shutil import rmtree
17 from django.conf import settings
18 from fnpdjango.utils.settings import LazyUGettextLazy as _
21 # For convenience configure settings if they are not pre-configured or if we
22 # haven't been provided settings to use by environment variable.
23 if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'):
25 media_root = tempfile.mkdtemp(prefix='djangotest_')
30 'ENGINE': 'django.db.backends.sqlite3',
36 'django.contrib.admin',
37 'django.contrib.auth',
38 'django.contrib.contenttypes',
39 'django.contrib.messages',
40 'django.contrib.sessions',
41 'django.contrib.sites',
47 MEDIA_ROOT=media_root,
48 STATIC_URL='/static/',
49 MIDDLEWARE_CLASSES=[ # Django <= 1.9
50 'django.middleware.common.CommonMiddleware',
51 'fnpdjango.middleware.URLLocaleMiddleware',
52 'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
53 'django.contrib.sessions.middleware.SessionMiddleware',
54 'django.contrib.auth.middleware.AuthenticationMiddleware',
55 'django.contrib.messages.middleware.MessageMiddleware',
58 'django.middleware.common.CommonMiddleware',
59 'fnpdjango.middleware.URLLocaleMiddleware',
60 'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
61 'django.contrib.sessions.middleware.SessionMiddleware',
62 'django.contrib.auth.middleware.AuthenticationMiddleware',
63 'django.contrib.messages.middleware.MessageMiddleware',
65 FNPDJANGO_REALIP = True,
66 ROOT_URLCONF='tests.urls',
69 'BACKEND': 'django.template.backends.django.DjangoTemplates',
72 'context_processors': [
73 'django.contrib.auth.context_processors.auth',
74 'django.contrib.messages.context_processors.messages',
79 TEST_LAZY_UGETTEXT_LAZY=_("Lazy setting."),
90 from django.test.runner import DiscoverRunner
93 from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
96 def runtests(*test_args, **kwargs):
97 """Actual test suite entry point."""
100 parent = dirname(abspath(__file__))
101 sys.path.insert(0, parent)
105 from django import setup
111 test_runner = DiscoverRunner(
112 verbosity=kwargs.get('verbosity', 1),
113 interactive=kwargs.get('interactive', False),
114 failfast=kwargs.get('failfast'))
115 failures = test_runner.run_tests(test_args)
120 if __name__ == '__main__':
121 parser = OptionParser()
122 parser.add_option('--failfast', action='store_true',
123 default=False, dest='failfast')
125 (options, args) = parser.parse_args()
127 runtests(failfast=options.failfast, *args)