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 TEMPLATE_CONTEXT_PROCESSORS=(
57 "django.core.context_processors.debug",
58 "django.core.context_processors.i18n",
59 "django.core.context_processors.tz",
60 "django.core.context_processors.request",
65 from django.test.runner import DiscoverRunner
68 from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
71 def runtests(*test_args, **kwargs):
72 """Actual test suite entry point."""
75 parent = dirname(abspath(__file__))
76 sys.path.insert(0, parent)
80 from django import setup
86 test_runner = DiscoverRunner(
87 verbosity=kwargs.get('verbosity', 1),
88 interactive=kwargs.get('interactive', False),
89 failfast=kwargs.get('failfast'))
90 failures = test_runner.run_tests(test_args)
93 if __name__ == '__main__':
94 parser = OptionParser()
95 parser.add_option('--failfast', action='store_true',
96 default=False, dest='failfast')
98 (options, args) = parser.parse_args()
100 runtests(failfast=options.failfast, *args)