diff options
| author | Ian Foote <ian@feete.org> | 2018-11-15 14:43:58 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-11-15 09:43:58 -0500 |
| commit | e1fc07c047f8e46c2cea0120f44011fc458f1e91 (patch) | |
| tree | e56a421fe9ea6ff5a053b72c36e914139de2f07b /tests | |
| parent | cd40306854bdeec7d961e3715fba0ba9f72f2f88 (diff) | |
Fixed #17930 -- Allowed ORing (|) with sliced QuerySets.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/queries/tests.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 25e3b283ec..a30403a153 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -2140,6 +2140,37 @@ class SubqueryTests(TestCase): ) +@skipUnlessDBFeature('allow_sliced_subqueries_with_in') +class QuerySetBitwiseOperationTests(TestCase): + @classmethod + def setUpTestData(cls): + school = School.objects.create() + cls.room_1 = Classroom.objects.create(school=school, has_blackboard=False, name='Room 1') + cls.room_2 = Classroom.objects.create(school=school, has_blackboard=True, name='Room 2') + cls.room_3 = Classroom.objects.create(school=school, has_blackboard=True, name='Room 3') + cls.room_4 = Classroom.objects.create(school=school, has_blackboard=False, name='Room 4') + + def test_or_with_rhs_slice(self): + qs1 = Classroom.objects.filter(has_blackboard=True) + qs2 = Classroom.objects.filter(has_blackboard=False)[:1] + self.assertCountEqual(qs1 | qs2, [self.room_1, self.room_2, self.room_3]) + + def test_or_with_lhs_slice(self): + qs1 = Classroom.objects.filter(has_blackboard=True)[:1] + qs2 = Classroom.objects.filter(has_blackboard=False) + self.assertCountEqual(qs1 | qs2, [self.room_1, self.room_2, self.room_4]) + + def test_or_with_both_slice(self): + qs1 = Classroom.objects.filter(has_blackboard=False)[:1] + qs2 = Classroom.objects.filter(has_blackboard=True)[:1] + self.assertCountEqual(qs1 | qs2, [self.room_1, self.room_2]) + + def test_or_with_both_slice_and_ordering(self): + qs1 = Classroom.objects.filter(has_blackboard=False).order_by('-pk')[:1] + qs2 = Classroom.objects.filter(has_blackboard=True).order_by('-name')[:1] + self.assertCountEqual(qs1 | qs2, [self.room_3, self.room_4]) + + class CloneTests(TestCase): def test_evaluated_queryset_as_argument(self): |
