1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
7
from storm.zope.zstorm import global_zstorm
9
from launchpadresults.testing.factories import TestFactory
14
"TestCaseWithFactory",
18
class DatabaseTestCase(unittest.TestCase):
20
def _assertSQL(self, func, expected_statement, all_statements):
21
regexp = re.compile("\s")
24
statement = regexp.sub("", statement)
27
func(crush(expected_statement),
28
[crush(statement) for statement in all_statements])
30
def assertSQLIn(self, expected_statement, all_statements):
31
"""Ensure that C{expected_statement} is in C{all_statements}.
33
Whitespace is completely collapsed before statements are compared.
35
self._assertSQL(self.assertIn, expected_statement, all_statements)
37
def assertSQLNotIn(self, expected_statement, all_statements):
38
"""Ensure that C{expected_statement} is not in C{all_statements}.
40
Whitespace is completely collapsed before statements are compared.
42
self._assertSQL(self.assertNotIn, expected_statement, all_statements)
45
# Flush stores to try to catch improper statements unflushed.
46
for name, store in global_zstorm.iterstores():
49
# Clear the alive cache *before* abort is called, to prevent an useless
50
# loop over those objects in invalidate. Ideally, it whould be in
51
# DatabaseLayer, but FunctionalTestCase calls abort before that
52
# DatabaseLayer.testTearDown is called.
53
for name, store in global_zstorm.iterstores():
55
super(DatabaseTestCase, self).tearDown()
58
class TestCase(DatabaseTestCase):
63
class TestCaseWithFactory(TestCase):
66
super(TestCaseWithFactory, self).setUp()
67
self.factory = TestFactory()