diff options
Diffstat (limited to 'tests/expressions/tests.py')
| -rw-r--r-- | tests/expressions/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 5f61f65ac0..ac06c212ea 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -749,6 +749,24 @@ class BasicExpressionsTests(TestCase): ) self.assertCountEqual(subquery_test2, [self.foobar_ltd]) + def test_lookups_subquery(self): + smallest_company = Company.objects.order_by("num_employees").values("name")[:1] + for lookup in CharField.get_lookups(): + if lookup == "isnull": + continue # not allowed, rhs must be a literal boolean. + if ( + lookup == "in" + and not connection.features.allow_sliced_subqueries_with_in + ): + continue + if lookup == "range": + rhs = (Subquery(smallest_company), Subquery(smallest_company)) + else: + rhs = Subquery(smallest_company) + with self.subTest(lookup=lookup): + qs = Company.objects.filter(**{f"name__{lookup}": rhs}) + self.assertGreater(len(qs), 0) + def test_uuid_pk_subquery(self): u = UUIDPK.objects.create() UUID.objects.create(uuid_fk=u) |
