2 # This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
6 Creates a simple Django configuration and runs tests for fnpdjango.
10 from os.path import dirname, abspath
11 from optparse import OptionParser
12 from shutil import rmtree
14 from django.conf import settings
15 from fnpdjango.utils.settings import LazyUGettextLazy as _
18 # For convenience configure settings if they are not pre-configured or if we
19 # haven't been provided settings to use by environment variable.
20 if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'):
22 media_root = tempfile.mkdtemp(prefix='djangotest_')
27 'ENGINE': 'django.db.backends.sqlite3',
33 'django.contrib.admin',
34 'django.contrib.auth',
35 'django.contrib.contenttypes',
36 'django.contrib.messages',
37 'django.contrib.sessions',
38 'django.contrib.sites',
39 'django.contrib.staticfiles',
45 MEDIA_ROOT=media_root,
46 STATIC_URL='/static/',
47 STATIC_ROOT='./static/',
48 STATICFILES_STORAGE = 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage',
50 'django.middleware.common.CommonMiddleware',
51 'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
52 'django.contrib.sessions.middleware.SessionMiddleware',
53 'django.contrib.auth.middleware.AuthenticationMiddleware',
54 'django.contrib.messages.middleware.MessageMiddleware',
56 FNPDJANGO_REALIP = True,
57 ROOT_URLCONF='tests.urls',
60 'BACKEND': 'django.template.backends.django.DjangoTemplates',
63 'context_processors': [
64 'django.contrib.auth.context_processors.auth',
65 'django.contrib.messages.context_processors.messages',
70 TEST_LAZY_UGETTEXT_LAZY=_("Lazy setting."),
82 from django.test.runner import DiscoverRunner
85 def runtests(*test_args, **kwargs):
86 """Actual test suite entry point."""
89 parent = dirname(abspath(__file__))
90 sys.path.insert(0, parent)
92 from django import setup
95 test_runner = DiscoverRunner(
96 verbosity=kwargs.get('verbosity', 1),
97 interactive=kwargs.get('interactive', False),
98 failfast=kwargs.get('failfast'))
99 failures = test_runner.run_tests(test_args)
104 if __name__ == '__main__':
105 parser = OptionParser()
106 parser.add_option('--failfast', action='store_true',
107 default=False, dest='failfast')
109 (options, args) = parser.parse_args()
111 runtests(failfast=options.failfast, *args)