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")
|
self.assertEqual(obj.name, "p1")
|
||||||
|
|
||||||
def test_defer_select_related_raises_invalid_query(self):
|
def test_defer_select_related_raises_invalid_query(self):
|
||||||
# When we defer a field and also select_related it, the query is
|
msg = (
|
||||||
# invalid and raises an exception.
|
'Field Primary.related cannot be both deferred and traversed '
|
||||||
with self.assertRaises(InvalidQuery):
|
'using select_related at the same time.'
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(InvalidQuery, msg):
|
||||||
Primary.objects.defer("related").select_related("related")[0]
|
Primary.objects.defer("related").select_related("related")[0]
|
||||||
|
|
||||||
def test_only_select_related_raises_invalid_query(self):
|
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]
|
Primary.objects.only("name").select_related("related")[0]
|
||||||
|
|
||||||
def test_defer_foreign_keys_are_deferred_and_not_traversed(self):
|
def test_defer_foreign_keys_are_deferred_and_not_traversed(self):
|
||||||
|
|
Loading…
Reference in New Issue