Skip to content

Commit

Permalink
Add support in other databases.
Browse files Browse the repository at this point in the history
  • Loading branch information
WaVEV committed Sep 10, 2024
1 parent e23082c commit cdc9592
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions tests/queries/test_qs_combinators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit cdc9592

Please sign in to comment.