Commits

Mikhail Korobov committed b9979cd

Basic testing infrastructure

Comments (0)

Files changed (14)

+Running tests
+=============
+::
+
+    $ cd test_proj
+    $ ./test.sh
+
+
+Code coverage report
+====================
+
+Install django-coverage app::
+
+    $ pip install django-coverage
+
+Then run tests and open test_proj/_coverage/index.html file in browser.

test_proj/__init__.py

Empty file added.

test_proj/_coverage/noremove

Empty file added.

test_proj/manage.py

+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)

test_proj/settings.py

+# settings for django-admin-tools test project.
+import os
+PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
+
+DATABASE_ENGINE = 'sqlite3'
+DATABASE_NAME = ':memory:'
+SITE_ID = 1
+
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+TEMPLATE_CONTEXT_PROCESSORS = (
+    'django.core.context_processors.auth',
+    'django.core.context_processors.request',
+)
+
+ROOT_URLCONF = 'urls'
+
+TEMPLATE_DIRS = (
+    PROJECT_PATH + '/templates',
+)
+
+INSTALLED_APPS = [
+    'admin_tools.theming',
+    'admin_tools.menu',
+    'admin_tools.dashboard',
+
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'django.contrib.admin',
+
+    'test_app',
+]
+
+try:
+    import django_coverage
+    TEST_RUNNER = 'django_coverage.coverage_runner.run_tests'
+    COVERAGE_REPORT_HTML_OUTPUT_DIR = os.path.join(PROJECT_PATH, '_coverage')
+except ImportError:
+    pass

test_proj/templates/404.html

+404

test_proj/templates/500.html

+500

test_proj/test.sh

+#!/bin/sh
+
+default_tests='dashboard theming menu test_app'
+if [ $# -eq 0 ]
+then
+    ./manage.py test $default_tests
+else
+    ./manage.py test $*
+fi

test_proj/test_app/__init__.py

Empty file added.

test_proj/test_app/admin.py

+from django.contrib import admin
+from test_app.models import MyModel
+
+admin.site.register(MyModel)

test_proj/test_app/models.py

+from django.db import models
+
+class MyModel(models.Model):
+    pass

test_proj/test_app/tests.py

+from django.test import TestCase
+
+class AdminBasicTest(TestCase):
+    def test_admin_loads(self):
+        self.client.get('/admin/')

test_proj/test_app/views.py

+# Create your views here.

test_proj/urls.py

+from django.conf.urls.defaults import *
+
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    (r'^admin/', include(admin.site.urls)),
+    url(r'^admin_tools/', include('admin_tools.urls')),
+)