summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example_project/settings.py2
-rw-r--r--ishtar_common/tests.py24
2 files changed, 26 insertions, 0 deletions
diff --git a/example_project/settings.py b/example_project/settings.py
index a191b83b3..437c75673 100644
--- a/example_project/settings.py
+++ b/example_project/settings.py
@@ -229,6 +229,8 @@ OP_PREFIX = 'OP'
PRE_APPS = []
EXTRA_APPS = []
+TEST_RUNNER = 'ishtar_common.tests.ManagedModelTestRunner'
+
try:
from local_settings import *
except ImportError, e:
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index a00f8a174..6db425cab 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -29,6 +29,7 @@ from django.core.urlresolvers import reverse
from django.template.defaultfilters import slugify
from django.test import TestCase
from django.test.client import Client
+from django.test.simple import DjangoTestSuiteRunner
from ishtar_common import models
@@ -101,6 +102,29 @@ class WizardTestFormData(object):
test(test_object, final_step_response)
+class ManagedModelTestRunner(DjangoTestSuiteRunner):
+ """
+ Test runner that automatically makes all unmanaged models in your Django
+ project managed for the duration of the test run, so that one doesn't need
+ to execute the SQL manually to create them.
+ """
+ def setup_test_environment(self, *args, **kwargs):
+ from django.db.models.loading import get_models
+ self.unmanaged_models = [m for m in get_models()
+ if not m._meta.managed]
+ for m in self.unmanaged_models:
+ m._meta.managed = True
+ super(ManagedModelTestRunner, self).setup_test_environment(*args,
+ **kwargs)
+
+ def teardown_test_environment(self, *args, **kwargs):
+ super(ManagedModelTestRunner, self).teardown_test_environment(*args,
+ **kwargs)
+ # reset unmanaged models
+ for m in self.unmanaged_models:
+ m._meta.managed = False
+
+
class WizardTest(object):
url_name = None
wizard_name = ''