1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #373 -- Improved test coverage of tuple lookup checks.

This also removed unreachable checks.
This commit is contained in:
Bendeguz Csirmaz
2024-08-15 13:27:47 +08:00
committed by Sarah Boyce
parent 2a4321ba23
commit 347ab72c02
2 changed files with 37 additions and 29 deletions

View File

@@ -240,3 +240,28 @@ class TupleLookupsTests(TestCase):
self.assertSequenceEqual(
Contact.objects.filter(customer__isnull=subquery).order_by("id"), ()
)
def test_lookup_errors(self):
m_2_elements = "'%s' lookup of 'customer' field must have 2 elements"
m_2_elements_each = "'in' lookup of 'customer' field must have 2 elements each"
test_cases = (
({"customer": 1}, m_2_elements % "exact"),
({"customer": (1, 2, 3)}, m_2_elements % "exact"),
({"customer__in": (1, 2, 3)}, m_2_elements_each),
({"customer__in": ("foo", "bar")}, m_2_elements_each),
({"customer__gt": 1}, m_2_elements % "gt"),
({"customer__gt": (1, 2, 3)}, m_2_elements % "gt"),
({"customer__gte": 1}, m_2_elements % "gte"),
({"customer__gte": (1, 2, 3)}, m_2_elements % "gte"),
({"customer__lt": 1}, m_2_elements % "lt"),
({"customer__lt": (1, 2, 3)}, m_2_elements % "lt"),
({"customer__lte": 1}, m_2_elements % "lte"),
({"customer__lte": (1, 2, 3)}, m_2_elements % "lte"),
)
for kwargs, message in test_cases:
with (
self.subTest(kwargs=kwargs),
self.assertRaisesMessage(ValueError, message),
):
Contact.objects.get(**kwargs)