Commits

Mikhail Korobov committed 14d16e2

Unit/functional test separation

Comments (0)

Files changed (5)

+Testing of django-admin-tools
+=============================
+
 Running tests
-=============
-
+~~~~~~~~~~~~~
 Run 'runtests.sh' script.
 
+Run all tests::
+
+    $ ./runtests.sh
+
+Run only unit tests::
+
+    $ ./runtests.sh unit
+
+Run only tests for specified app::
+
+    $ ./runtests.sh dashboard
+
+Run only one test case::
+
+    $ ./runtests.sh dashboard.ManagementCommandTest
+
+Run only one test::
+
+    $ ./runtests.sh dashboard.ManagementCommandTest.test_customdashboard
+
 
 Code coverage report
-====================
-
+~~~~~~~~~~~~~~~~~~~~
 Install django-coverage app::
 
     $ pip install django-coverage
 
-Then run tests and open test_proj/_coverage/index.html file in browser.
+Then run tests and open test_proj/_coverage/index.html file in browser.
+
+
+Where tests live
+~~~~~~~~~~~~~~~~
+Unit tests should be put into appropriate module's tests.py.
+Functional/integration tests should be put somewhere into test_proj.

admin_tools/dashboard/management/commands/customdashboard.py

 from django.core.management.base import BaseCommand, CommandError
 from django.template.loader import render_to_string
 
-
 DEFAULT_FILE = 'dashboard.py'
 
 class Command(BaseCommand):

admin_tools/dashboard/tests.py

-from tempfile import mkstemp, mktemp
-from django.test import TestCase
+from tempfile import mktemp
+from unittest import TestCase
+from django.test import TestCase as DjangoTestCase
 from django.core import management
+from django.contrib.auth.models import User, Group
+
+from admin_tools.dashboard import AppIndexDashboard
 
 class ManagementCommandTest(TestCase):
     def test_customdashboard(self):
-        # check that customdashboard command don't raise exceptions
+        # check that customdashboard command doesn't raise exceptions
         file_name = mktemp()
         management.call_command('customdashboard', file=file_name)
         # and fails if file is already here
         except:
             pass
 
+class AppIndexDashboardTest(TestCase):
+    def test_models(self):
+        models = ['django.contrib.auth.models.User',
+                  'django.contrib.auth.models.Group']
+        board = AppIndexDashboard('Auth', models)
+        self.assertEqual(board.get_app_model_classes(), [User, Group])

admin_tools/dashboard/utils.py

     if app_label is not None and app_label in Registry.registry:
         return Registry.registry[app_label](app_title, model_list)
 
-    # try to discover a general app_index dashboard (with fallback to the 
+    # try to discover a general app_index dashboard (with fallback to the
     # default dashboard)
     dashboard_cls = getattr(
         settings,
 #!/bin/sh
-default_tests='dashboard theming menu test_app'
+default_unit='dashboard theming menu'
+default_all="$default_unit test_app"
 if [ $# -eq 0 ]
 then
-    test_proj/manage.py test $default_tests
+    test_proj/manage.py test $default_all
 else
-    test_proj/manage.py test $*
+    if [ $1 = 'unit' ]
+    then
+        test_proj/manage.py test $default_unit
+    else
+        test_proj/manage.py test $*
+    fi
 fi
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.