mirror of
https://github.com/django/django.git
synced 2025-08-31 15:57:45 +00:00
Fixed #33278 -- Improved error for connection/query attempts against disallowed databases in tests.
This commit is contained in:
parent
560ff988dd
commit
76f07b4fcf
4 changed files with 16 additions and 10 deletions
|
@ -2,7 +2,7 @@ from functools import wraps
|
|||
|
||||
from django.db import IntegrityError, connections, transaction
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
from django.test.testcases import TestData
|
||||
from django.test.testcases import DatabaseOperationForbidden, TestData
|
||||
|
||||
from .models import Car, Person, PossessedCar
|
||||
|
||||
|
@ -28,9 +28,9 @@ class TestTestCase(TestCase):
|
|||
"Add 'other' to test_utils.test_testcase.TestTestCase.databases to "
|
||||
"ensure proper test isolation and silence this failure."
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, message):
|
||||
with self.assertRaisesMessage(DatabaseOperationForbidden, message):
|
||||
connections['other'].connect()
|
||||
with self.assertRaisesMessage(AssertionError, message):
|
||||
with self.assertRaisesMessage(DatabaseOperationForbidden, message):
|
||||
connections['other'].temporary_connection()
|
||||
|
||||
def test_disallowed_database_queries(self):
|
||||
|
@ -39,7 +39,7 @@ class TestTestCase(TestCase):
|
|||
"Add 'other' to test_utils.test_testcase.TestTestCase.databases to "
|
||||
"ensure proper test isolation and silence this failure."
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, message):
|
||||
with self.assertRaisesMessage(DatabaseOperationForbidden, message):
|
||||
Car.objects.using('other').get()
|
||||
|
||||
def test_reset_sequences(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue