diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py index a8b3df8844..e7740b987c 100644 --- a/tests/queries/test_qs_combinators.py +++ b/tests/queries/test_qs_combinators.py @@ -5,7 +5,7 @@ from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test.utils import CaptureQueriesContext -from .models import Author, Celebrity, ExtraInfo, Number, ReservedName +from .models import Author, Celebrity, ExtraInfo, Number, Report, ReservedName @skipUnlessDBFeature("supports_select_union") @@ -125,23 +125,22 @@ def test_union_nested(self): def test_union_with_different_models(self): expected_result = { - "Angel Di Maria", - "Lionel Messi", - "Emiliano Martinez", - "Gabriel Marques", - "Jorge Luis Borges", - "Umberto Eco", + "Angel", + "Lionel", + "Emiliano", + "Demetrio", + "Daniel", + "Javier", } - Celebrity.objects.create(name="Angel Di Maria") - Celebrity.objects.create(name="Lionel Messi") - Celebrity.objects.create(name="Emiliano Martinez") - Celebrity.objects.create(name="Gabriel Marques") - e1 = ExtraInfo.objects.create(value=7, info="e1") - Author.objects.create(name="Gabriel Marques", num=1, extra=e1) - Author.objects.create(name="Jorge Luis Borges", num=2, extra=e1) - Author.objects.create(name="Umberto Eco", num=3, extra=e1) + Celebrity.objects.create(name="Angel") + Celebrity.objects.create(name="Lionel") + Celebrity.objects.create(name="Emiliano") + Celebrity.objects.create(name="Demetrio") + Report.objects.create(name="Demetrio") + Report.objects.create(name="Daniel") + Report.objects.create(name="Javier") qs1 = Celebrity.objects.values(alias=F("name")) - qs2 = Author.objects.values(alias_author=F("name")) + qs2 = Report.objects.values(alias_author=F("name")) qs_union = qs1.union(qs2).values("name") self.assertCountEqual((e["name"] for e in qs_union), expected_result) qs_union = qs1.union(qs2).all() @@ -488,13 +487,6 @@ def test_count_union_with_select_related(self): qs = Author.objects.select_related("extra").order_by() self.assertEqual(qs.union(qs).count(), 1) - def test_count_union_with_select_related_projected(self): - e1 = ExtraInfo.objects.create(value=1, info="e1") - a1 = Author.objects.create(name="a1", num=1, extra=e1) - qs = Author.objects.select_related("extra").values("pk", "name", "extra__value") - self.assertEqual(len(qs.union(qs)), 1) - self.assertEqual(qs.union(qs).first(), {"pk": a1.id, 'name': 'a1', 'extra__value': 1}) - @skipUnlessDBFeature("supports_select_difference") def test_count_difference(self): qs1 = Number.objects.filter(num__lt=10) @@ -507,6 +499,16 @@ def test_count_intersection(self): qs2 = Number.objects.filter(num__lte=5) self.assertEqual(qs1.intersection(qs2).count(), 1) + @skipUnlessDBFeature( + "supports_slicing_ordering_in_compound" + ) + def test_count_union_with_select_related_projected(self): + e1 = ExtraInfo.objects.create(value=1, info="e1") + a1 = Author.objects.create(name="a1", num=1, extra=e1) + qs = Author.objects.select_related("extra").values("pk", "name", "extra__value") + self.assertEqual(len(qs.union(qs)), 1) + self.assertEqual(qs.union(qs).first(), {"pk": a1.id, 'name': 'a1', 'extra__value': 1}) + def test_exists_union(self): qs1 = Number.objects.filter(num__gte=5) qs2 = Number.objects.filter(num__lte=5)