3 # This file is part of django-ssify, 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 django-ssify.
9 from __future__ import unicode_literals
12 from os.path import dirname, abspath
13 from optparse import OptionParser
15 from django.conf import settings
17 # For convenience configure settings if they are not pre-configured or if we
18 # haven't been provided settings to use by environment variable.
19 if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'):
22 'default': {'BACKEND':
23 'django.core.cache.backends.locmem.LocMemCache'},
25 'django.core.cache.backends.locmem.LocMemCache'},
29 'ENGINE': 'django.db.backends.sqlite3',
33 'django.contrib.auth',
34 'django.contrib.contenttypes',
35 'django.contrib.sessions',
36 'django.contrib.sites',
44 'django.middleware.csrf.CsrfViewMiddleware',
45 'ssify.middleware.SsiMiddleware',
46 'django.middleware.cache.UpdateCacheMiddleware',
47 'ssify.middleware.PrepareForCacheMiddleware',
48 'django.middleware.common.CommonMiddleware',
49 'django.contrib.sessions.middleware.SessionMiddleware',
50 'ssify.middleware.LocaleMiddleware',
51 'django.middleware.cache.FetchFromCacheMiddleware',
53 STATIC_URL='/static/',
54 ROOT_URLCONF='tests.urls',
56 SSIFY_DEBUG_VERBOSE=False,
57 TEMPLATE_CONTEXT_PROCESSORS=(
58 "django.core.context_processors.debug",
59 "django.core.context_processors.i18n",
60 "django.core.context_processors.tz",
61 "django.core.context_processors.request",
66 from django.test.runner import DiscoverRunner
69 from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
72 def runtests(*test_args, **kwargs):
73 """Actual test suite entry point."""
76 parent = dirname(abspath(__file__))
77 sys.path.insert(0, parent)
81 from django import setup
87 test_runner = DiscoverRunner(
88 verbosity=kwargs.get('verbosity', 1),
89 interactive=kwargs.get('interactive', False),
90 failfast=kwargs.get('failfast'))
91 failures = test_runner.run_tests(test_args)
94 if __name__ == '__main__':
95 parser = OptionParser()
96 parser.add_option('--failfast', action='store_true',
97 default=False, dest='failfast')
99 (options, args) = parser.parse_args()
101 runtests(failfast=options.failfast, *args)