~rvb/maas/maas-1.7-3399

« back to all changes in this revision

Viewing changes to src/maastesting/djangotestcase.py

Backports all the changes from trunk up to revision 3379 (i.e. all the changes before the change to the isolation level).

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
 
23
23
from django.conf import settings
24
 
from django.core.management import call_command
25
24
from django.core.management.commands import syncdb
26
25
from django.core.signals import request_started
27
26
from django.db import (
82
81
    """
83
82
 
84
83
 
85
 
def cleanup_db(testcase):
86
 
    # Force a flush of the db: this is called by test classes based on
87
 
    # django.test.TransactionTestCase at the beginning of each
88
 
    # TransactionTestCase test but not at the end.  The Django test runner
89
 
    # avoids any problem by running all the TestCase tests and *then*
90
 
    # all the TransactionTestCase tests.  Since we use nose, we don't
91
 
    # have that ordering and thus we need to manually flush the db after
92
 
    # each TransactionTestCase test.  Le Sigh.
93
 
    if getattr(testcase, 'multi_db', False):
94
 
        databases = connections
95
 
    else:
96
 
        databases = [DEFAULT_DB_ALIAS]
97
 
    for db in databases:
98
 
        call_command('flush', verbosity=0, interactive=False, database=db)
99
 
 
100
 
 
101
84
class TransactionTestCase(MAASTestCase, django.test.TransactionTestCase):
102
 
    """`TransactionTestCase` for Metal as a Service.
 
85
    """`TransactionTestCase` for MAAS.
103
86
 
104
87
    A version of MAASTestCase that supports transactions.
105
88
 
106
89
    The basic Django TestCase class uses transactions to speed up tests
107
 
    so this class should be used when tests involve transactions.
 
90
    so this class should only be used when tests involve transactions.
108
91
    """
109
 
    def _fixture_teardown(self):
110
 
        cleanup_db(self)
111
 
        super(TransactionTestCase, self)._fixture_teardown()
112
92
 
113
93
 
114
94
class TestModelMixin: