diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-09 13:30:23 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-09 13:30:23 +0100 |
commit | a9304b80e3b4a69312ba1c988f1c9f170f332f43 (patch) | |
tree | 1e8aee138f6bd99bc401156418ddbeed3089ff6a | |
parent | 3736b45dc99e7cdfe38e674e7fa0ad4cf730e996 (diff) | |
download | Ishtar-a9304b80e3b4a69312ba1c988f1c9f170f332f43.tar.bz2 Ishtar-a9304b80e3b4a69312ba1c988f1c9f170f332f43.zip |
tests: force managing of unmanage tables
-rw-r--r-- | example_project/settings.py | 2 | ||||
-rw-r--r-- | ishtar_common/tests.py | 24 |
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 = '' |