1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #33278 -- Improved error for connection/query attempts against disallowed databases in tests.

This commit is contained in:
SwastikTripathi
2021-11-12 23:06:13 +05:30
committed by Mariusz Felisiak
parent 560ff988dd
commit 76f07b4fcf
4 changed files with 16 additions and 10 deletions

View File

@@ -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):