diff options
| author | Bendeguz Csirmaz <csirmazbendeguz@gmail.com> | 2024-08-15 13:27:47 +0800 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-09-11 11:23:01 +0200 |
| commit | 347ab72c0253796d7ac3d1396dcd3b220ad18af1 (patch) | |
| tree | efbfc0ffd873493b548241aa19e56941f8502360 /tests/foreign_object | |
| parent | 2a4321ba23042c962f8dc966779239244c6e4402 (diff) | |
Refs #373 -- Improved test coverage of tuple lookup checks.
This also removed unreachable checks.
Diffstat (limited to 'tests/foreign_object')
| -rw-r--r-- | tests/foreign_object/test_tuple_lookups.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/foreign_object/test_tuple_lookups.py b/tests/foreign_object/test_tuple_lookups.py index cf080d084b..2742d6e93d 100644 --- a/tests/foreign_object/test_tuple_lookups.py +++ b/tests/foreign_object/test_tuple_lookups.py @@ -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) |
