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',
34 'django.contrib.auth',
35 'django.contrib.contenttypes',
36 'django.contrib.sessions',
37 'django.contrib.sites',
43 MEDIA_ROOT=media_root,
44 STATIC_URL='/static/',
45 MIDDLEWARE_CLASSES=[ # Django <= 1.9
46 'django.middleware.common.CommonMiddleware',
47 'fnpdjango.middleware.URLLocaleMiddleware',
48 'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
51 'django.middleware.common.CommonMiddleware',
52 'fnpdjango.middleware.URLLocaleMiddleware',
53 'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
55 FNPDJANGO_REALIP = True,
56 ROOT_URLCONF='tests.urls',
59 'BACKEND': 'django.template.backends.django.DjangoTemplates',
63 TEST_LAZY_UGETTEXT_LAZY=_("Lazy setting."),
70 from django.test.runner import DiscoverRunner
73 from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
76 def runtests(*test_args, **kwargs):
77 """Actual test suite entry point."""
80 parent = dirname(abspath(__file__))
81 sys.path.insert(0, parent)
85 from django import setup
91 test_runner = DiscoverRunner(
92 verbosity=kwargs.get('verbosity', 1),
93 interactive=kwargs.get('interactive', False),
94 failfast=kwargs.get('failfast'))
95 failures = test_runner.run_tests(test_args)
100 if __name__ == '__main__':
101 parser = OptionParser()
102 parser.add_option('--failfast', action='store_true',
103 default=False, dest='failfast')
105 (options, args) = parser.parse_args()
107 runtests(failfast=options.failfast, *args)