Commits

Sergey Maranchuk committed 76be129

replace runtests.sh to python script; add test_suite to setup.py refs #29

Comments (0)

Files changed (4)

djangobb_forum/tests/settings.py

-DATABASES = {
-    'default': {
-        'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': ':memory:',
-    }
-}
-
-MEDIA_URL = '/media/'
-STATIC_URL = '/static/'
-
-SECRET_KEY = 'wm4bts-m2@y0pwb$=_lf-&k)(f$6g6gw7h_*)-^!u@#a64!9q3'
-
-SITE_ID = 1
-
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
-    'django.template.loaders.filesystem.Loader',
-    'django.template.loaders.app_directories.Loader',
-)
-
-
-MIDDLEWARE_CLASSES = (
-    'django.middleware.common.CommonMiddleware',
-    'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
-    'django.contrib.auth.middleware.AuthenticationMiddleware',
-    'django.contrib.messages.middleware.MessageMiddleware',
-    'django.middleware.locale.LocaleMiddleware',
-    'pagination.middleware.PaginationMiddleware',
-    'django.middleware.transaction.TransactionMiddleware',
-    'djangobb_forum.middleware.LastLoginMiddleware',
-    'djangobb_forum.middleware.UsersOnline',
-)
-
-ROOT_URLCONF = 'djangobb_forum.tests.urls'
-
-INSTALLED_APPS = (
-    'django.contrib.auth',
-    'django.contrib.contenttypes',
-    'django.contrib.sessions',
-    'django.contrib.sites',
-    'django.contrib.messages',
-    'django.contrib.staticfiles',
-    'django.contrib.sitemaps',
-    'django.contrib.humanize',
-
-    'haystack',
-    'pagination',
-
-    'djangobb_forum',
-)
-
-TEMPLATE_CONTEXT_PROCESSORS = (
-    'django.contrib.auth.context_processors.auth',
-    'django.core.context_processors.debug',
-    'django.core.context_processors.i18n',
-    'django.core.context_processors.media',
-    'django.core.context_processors.static',
-    'django.core.context_processors.request',
-    'django.contrib.messages.context_processors.messages',
-    'djangobb_forum.context_processors.forum_settings',
-)
-
-PASSWORD_HASHERS = (
-    'django.contrib.auth.hashers.SHA1PasswordHasher',
-    'django.contrib.auth.hashers.MD5PasswordHasher',
-)
-
-DEFAULT_FILE_STORAGE = 'inmemorystorage.InMemoryStorage'
-
-LOGIN_REDIRECT_URL = '/forum/'
-LOGIN_URL = '/forum/account/signin/'
-
-HAYSTACK_SITECONF = 'djangobb_forum.tests.search_sites'
-HAYSTACK_SEARCH_ENGINE = 'dummy'
+#!/usr/bin/env python
+import sys
+import os
+from os.path import dirname, abspath
+from optparse import OptionParser
+
+from django.conf import settings, global_settings
+
+# For convenience configure settings if they are not pre-configured or if we
+# haven't been provided settings to use by environment variable.
+if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'):
+    settings.configure(
+        DATABASES={
+            'default': {
+                'ENGINE': 'django.db.backends.sqlite3',
+            }
+        },
+        INSTALLED_APPS=(
+            'django.contrib.auth',
+            'django.contrib.contenttypes',
+            'django.contrib.sessions',
+            'django.contrib.sites',
+            'django.contrib.messages',
+            'django.contrib.staticfiles',
+            'django.contrib.sitemaps',
+            'django.contrib.humanize',
+
+            'haystack',
+            'pagination',
+
+            'djangobb_forum',
+        ),
+        MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES + (
+                'django.middleware.locale.LocaleMiddleware',
+                'pagination.middleware.PaginationMiddleware',
+                'django.middleware.transaction.TransactionMiddleware',
+                'djangobb_forum.middleware.LastLoginMiddleware',
+                'djangobb_forum.middleware.UsersOnline',
+        ),
+        TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
+            'djangobb_forum.context_processors.forum_settings',
+        ),
+        PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
+        ROOT_URLCONF='djangobb_forum.tests.urls',
+        DEBUG=False,
+        SITE_ID=1,
+        HAYSTACK_SITECONF='djangobb_forum.tests.search_sites',
+        HAYSTACK_SEARCH_ENGINE='dummy',
+    )
+
+from django.test.simple import DjangoTestSuiteRunner
+
+
+def runtests(*test_args, **kwargs):
+    if 'south' in settings.INSTALLED_APPS:
+        from south.management.commands import patch_for_test_db_setup
+        patch_for_test_db_setup()
+
+    if not test_args:
+        test_args = ['djangobb_forum']
+    parent = dirname(abspath(__file__))
+    sys.path.insert(0, parent)
+    test_runner = DjangoTestSuiteRunner(verbosity=kwargs.get('verbosity', 1), interactive=kwargs.get('interactive', False), failfast=kwargs.get('failfast'))
+    failures = test_runner.run_tests(test_args)
+    sys.exit(failures)
+
+if __name__ == '__main__':
+    parser = OptionParser()
+    parser.add_option('--failfast', action='store_true', default=False, dest='failfast')
+
+    (options, args) = parser.parse_args()
+
+    runtests(failfast=options.failfast, *args)

runtests.sh

-#!/bin/bash
-export PYTHONPATH=$PYTHONPATH:$PWD
-django-admin.py  test --settings=djangobb_forum.tests.settings djangobb_forum
             'setuptools'
             ],
     keywords='django forum bb',
+    test_suite='runtests.runtests',
     cmdclass={'build': build, 'install_lib': install_lib,
         'compile_translations': compile_translations}
 )