mirror of https://github.com/django/django.git
Used assertRaisesMessage in a couple defer tests.
This commit is contained in:
parent
b1b05a017a
commit
353d436e7c
|
@ -112,13 +112,19 @@ class DeferTests(AssertionMixin, TestCase):
|
|||
self.assertEqual(obj.name, "p1")
|
||||
|
||||
def test_defer_select_related_raises_invalid_query(self):
|
||||
# When we defer a field and also select_related it, the query is
|
||||
# invalid and raises an exception.
|
||||
with self.assertRaises(InvalidQuery):
|
||||
msg = (
|
||||
'Field Primary.related cannot be both deferred and traversed '
|
||||
'using select_related at the same time.'
|
||||
)
|
||||
with self.assertRaisesMessage(InvalidQuery, msg):
|
||||
Primary.objects.defer("related").select_related("related")[0]
|
||||
|
||||
def test_only_select_related_raises_invalid_query(self):
|
||||
with self.assertRaises(InvalidQuery):
|
||||
msg = (
|
||||
'Field Primary.related cannot be both deferred and traversed using '
|
||||
'select_related at the same time.'
|
||||
)
|
||||
with self.assertRaisesMessage(InvalidQuery, msg):
|
||||
Primary.objects.only("name").select_related("related")[0]
|
||||
|
||||
def test_defer_foreign_keys_are_deferred_and_not_traversed(self):
|
||||
|
|
Loading…
Reference in New Issue