8d27ecf0c65dad9904016080dd3368ea58f9ab06
[django-ssify.git] / runtests.py
1 #!/usr/bin/env python
2 import sys
3 import os
4 from os.path import dirname, abspath
5 from optparse import OptionParser
6
7 from django.conf import settings, global_settings
8
9 # For convenience configure settings if they are not pre-configured or if we
10 # haven't been provided settings to use by environment variable.
11 if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'):
12     settings.configure(
13         CACHES={
14             'default': {'BACKEND':
15                         'django.core.cache.backends.locmem.LocMemCache'},
16             'ssify': {'BACKEND':
17                       'django.core.cache.backends.locmem.LocMemCache'},
18         },
19         DATABASES={
20             'default': {
21                 'ENGINE': 'django.db.backends.sqlite3',
22             }
23         },
24         INSTALLED_APPS=[
25             'django.contrib.auth',
26             'django.contrib.contenttypes',
27             'django.contrib.sessions',
28             'django.contrib.sites',
29
30             'ssify',
31             'tests',
32         ],
33         MEDIA_URL='/media/',
34         MIDDLEWARE_CLASSES=[
35             'ssify.middleware.SsiMiddleware',
36             'django.middleware.cache.UpdateCacheMiddleware',
37             'ssify.middleware.PrepareForCacheMiddleware',
38             'django.middleware.common.CommonMiddleware',
39             'django.middleware.cache.FetchFromCacheMiddleware',
40         ],
41         STATIC_URL='/static/',
42         ROOT_URLCONF='tests.urls',
43         SITE_ID=1,
44         SSIFY_DEBUG_VERBOSE=False,
45         TEMPLATE_CONTEXT_PROCESSORS=(
46             "django.core.context_processors.debug",
47             "django.core.context_processors.i18n",
48             "django.core.context_processors.tz",
49             "django.core.context_processors.request",
50         ),
51     )
52
53 from django.test.simple import DjangoTestSuiteRunner
54
55
56 def runtests(*test_args, **kwargs):
57     if 'south' in settings.INSTALLED_APPS:
58         from south.management.commands import patch_for_test_db_setup
59         patch_for_test_db_setup()
60
61     if not test_args:
62         test_args = ['tests']
63     parent = dirname(abspath(__file__))
64     sys.path.insert(0, parent)
65     test_runner = DjangoTestSuiteRunner(
66         verbosity=kwargs.get('verbosity', 1),
67         interactive=kwargs.get('interactive', False),
68         failfast=kwargs.get('failfast'))
69     failures = test_runner.run_tests(test_args)
70     sys.exit(failures)
71
72 if __name__ == '__main__':
73     parser = OptionParser()
74     parser.add_option('--failfast', action='store_true',
75                       default=False, dest='failfast')
76
77     (options, args) = parser.parse_args()
78
79     runtests(failfast=options.failfast, *args)