1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #24652 -- Disallowed query execution in SimpleTestCase subclasses.

Thanks to Tim and Anssi for the review.
This commit is contained in:
Simon Charette
2015-04-16 16:19:30 -04:00
parent ead36e8a47
commit c15b0c2792
4 changed files with 64 additions and 0 deletions

View File

@@ -914,3 +914,21 @@ class OverrideSettingsTests(TestCase):
with self.settings(STATICFILES_DIRS=[test_path]):
finder = get_finder('django.contrib.staticfiles.finders.FileSystemFinder')
self.assertIn(expected_location, finder.locations)
class DisallowedDatabaseQueriesTests(SimpleTestCase):
def test_disallowed_database_queries(self):
expected_message = (
"Database queries aren't allowed in SimpleTestCase. "
"Either use TestCase or TransactionTestCase to ensure proper test isolation or "
"set DisallowedDatabaseQueriesTests.allow_database_queries to True to silence this failure."
)
with self.assertRaisesMessage(AssertionError, expected_message):
Car.objects.first()
class AllowedDatabaseQueriesTests(SimpleTestCase):
allow_database_queries = True
def test_allowed_database_queries(self):
Car.objects.first()