diff options
| author | Simon Charette <charette.s@gmail.com> | 2015-04-16 16:19:30 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2015-05-20 12:50:41 -0400 |
| commit | c15b0c27927afd141d311dd9bfe68540cf44a8d6 (patch) | |
| tree | c2c5771a671270b59f05b4bdfbb9b3e76213cbbd /tests/test_utils/tests.py | |
| parent | ead36e8a471389a6032d825c8245245ebb89ea5d (diff) | |
Fixed #24652 -- Disallowed query execution in SimpleTestCase subclasses.
Thanks to Tim and Anssi for the review.
Diffstat (limited to 'tests/test_utils/tests.py')
| -rw-r--r-- | tests/test_utils/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 57c0e6c2e7..dd68acdff9 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -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() |
