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 | 1aa58f90a149d7de7813dcf45fe8c1fb04a63143 (patch) | |
| tree | 1e8aee138f6bd99bc401156418ddbeed3089ff6a /ishtar_common | |
| parent | acdb5dcd125d95f5e8f9a6d2a7f80bfb17e74b33 (diff) | |
| download | Ishtar-1aa58f90a149d7de7813dcf45fe8c1fb04a63143.tar.bz2 Ishtar-1aa58f90a149d7de7813dcf45fe8c1fb04a63143.zip  | |
tests: force managing of unmanage tables
Diffstat (limited to 'ishtar_common')
| -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 = ''  | 
