diff options
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 24 |
1 files changed, 24 insertions, 0 deletions
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 = '' |