Skip to content

Commit

Permalink
Modernize spelling for assertQuerySetEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Dec 18, 2023
1 parent 4d4a08a commit 63d291f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
6 changes: 6 additions & 0 deletions polymorphic/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import django

if django.VERSION < (4, 2): # TODO: remove when dropping support for Django < 4.2
from django.test.testcases import TransactionTestCase

TransactionTestCase.assertQuerySetEqual = TransactionTestCase.assertQuerysetEqual
12 changes: 6 additions & 6 deletions polymorphic/tests/test_multidb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def test_save_to_non_default_database(self):
Model2B.objects.create(field1="B1", field2="B2")
Model2D(field1="D1", field2="D2", field3="D3", field4="D4").save()

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Model2A.objects.order_by("id"),
[Model2B, Model2D],
transform=lambda o: o.__class__,
)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Model2A.objects.db_manager("secondary").order_by("id"),
[Model2A, Model2C],
transform=lambda o: o.__class__,
Expand All @@ -44,26 +44,26 @@ def test_instance_of_filter_on_non_default_database(self):
ModelY.objects.db_manager("secondary").create(field_b="Y", field_y="Y")

objects = Base.objects.db_manager("secondary").filter(instance_of=Base)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Base, ModelX, ModelY],
transform=lambda o: o.__class__,
ordered=False,
)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Base.objects.db_manager("secondary").filter(instance_of=ModelX),
[ModelX],
transform=lambda o: o.__class__,
)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Base.objects.db_manager("secondary").filter(instance_of=ModelY),
[ModelY],
transform=lambda o: o.__class__,
)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Base.objects.db_manager("secondary").filter(
Q(instance_of=ModelX) | Q(instance_of=ModelY)
),
Expand Down
38 changes: 19 additions & 19 deletions polymorphic/tests/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_simple_inheritance(self):
self.create_model2abcd()

objects = Model2A.objects.all()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2A, Model2B, Model2C, Model2D],
transform=lambda o: o.__class__,
Expand Down Expand Up @@ -324,7 +324,7 @@ def test_non_polymorphic(self):
self.create_model2abcd()

objects = list(Model2A.objects.all().non_polymorphic())
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2A, Model2A, Model2A, Model2A],
transform=lambda o: o.__class__,
Expand All @@ -336,23 +336,23 @@ def test_get_real_instances(self):

# from queryset
objects = qs.get_real_instances()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2A, Model2B, Model2C, Model2D],
transform=lambda o: o.__class__,
)

# from a manual list
objects = Model2A.objects.get_real_instances(list(qs))
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2A, Model2B, Model2C, Model2D],
transform=lambda o: o.__class__,
)

# from empty list
objects = Model2A.objects.get_real_instances([])
self.assertQuerysetEqual(objects, [], transform=lambda o: o.__class__)
self.assertQuerySetEqual(objects, [], transform=lambda o: o.__class__)

def test_queryset_missing_derived(self):
a = Model2A.objects.create(field1="A1")
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_translate_polymorphic_q_object(self):

q = Model2A.translate_polymorphic_Q_object(Q(instance_of=Model2C))
objects = Model2A.objects.filter(q)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects, [Model2C, Model2D], transform=lambda o: o.__class__, ordered=False
)

Expand Down Expand Up @@ -505,7 +505,7 @@ def test_manytomany_field(self):
# no pretty printing
ModelShow1_plain.objects.create(field1="abc")
ModelShow2_plain.objects.create(field1="abc", field2="def")
self.assertQuerysetEqual(
self.assertQuerySetEqual(
ModelShow1_plain.objects.all(),
[ModelShow1_plain, ModelShow2_plain],
transform=lambda o: o.__class__,
Expand All @@ -516,7 +516,7 @@ def test_extra_method(self):
a, b, c, d = self.create_model2abcd()

objects = Model2A.objects.extra(where=[f"id IN ({b.id}, {c.id})"])
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects, [Model2B, Model2C], transform=lambda o: o.__class__, ordered=False
)

Expand All @@ -525,7 +525,7 @@ def test_extra_method(self):
where=["field1 = 'A1' OR field1 = 'B1'"],
order_by=["-id"],
)
self.assertQuerysetEqual(objects, [Model2B, Model2A], transform=lambda o: o.__class__)
self.assertQuerySetEqual(objects, [Model2B, Model2A], transform=lambda o: o.__class__)

ModelExtraA.objects.create(field1="A1")
ModelExtraB.objects.create(field1="B1", field2="B2")
Expand Down Expand Up @@ -556,39 +556,39 @@ def test_instance_of_filter(self):
self.create_model2abcd()

objects = Model2A.objects.instance_of(Model2B)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2B, Model2C, Model2D],
transform=lambda o: o.__class__,
ordered=False,
)

objects = Model2A.objects.filter(instance_of=Model2B)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2B, Model2C, Model2D],
transform=lambda o: o.__class__,
ordered=False,
)

objects = Model2A.objects.filter(Q(instance_of=Model2B))
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2B, Model2C, Model2D],
transform=lambda o: o.__class__,
ordered=False,
)

objects = Model2A.objects.not_instance_of(Model2B)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects, [Model2A], transform=lambda o: o.__class__, ordered=False
)

def test_polymorphic___filter(self):
self.create_model2abcd()

objects = Model2A.objects.filter(Q(Model2B___field2="B2") | Q(Model2C___field3="C3"))
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects, [Model2B, Model2C], transform=lambda o: o.__class__, ordered=False
)

Expand All @@ -599,7 +599,7 @@ def test_polymorphic_applabel___filter(self):
objects = Model2A.objects.filter(
Q(tests__Model2B___field2="B2") | Q(tests__Model2C___field3="C3")
)
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects, [Model2B, Model2C], transform=lambda o: o.__class__, ordered=False
)

Expand Down Expand Up @@ -645,7 +645,7 @@ def test_delete(self):

oa.delete()
objects = Model2A.objects.all()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[Model2A, Model2C, Model2D],
transform=lambda o: o.__class__,
Expand Down Expand Up @@ -748,7 +748,7 @@ def test_user_defined_manager(self):

# MyManager should reverse the sorting of field1
objects = ModelWithMyManager.objects.all()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[(ModelWithMyManager, "D1b", "D4b"), (ModelWithMyManager, "D1a", "D4a")],
transform=lambda o: (o.__class__, o.field1, o.field4),
Expand All @@ -764,7 +764,7 @@ def test_user_defined_manager_as_secondary(self):

# MyManager should reverse the sorting of field1
objects = ModelWithMyManagerNoDefault.my_objects.all()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[
(ModelWithMyManagerNoDefault, "D1b", "D4b"),
Expand Down Expand Up @@ -792,7 +792,7 @@ def test_user_defined_queryset_as_manager(self):
ModelWithMyManager2.objects.create(field1="D1b", field4="D4b")

objects = ModelWithMyManager2.objects.all()
self.assertQuerysetEqual(
self.assertQuerySetEqual(
objects,
[(ModelWithMyManager2, "D1a", "D4a"), (ModelWithMyManager2, "D1b", "D4b")],
transform=lambda o: (o.__class__, o.field1, o.field4),
Expand Down
6 changes: 3 additions & 3 deletions polymorphic/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def test_for_query_result_incomplete_with_inheritance(self):
bottom.save()

expected_queryset = [top, middle, bottom]
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Top.objects.order_by("pk"), [repr(r) for r in expected_queryset], **transform_arg
)

expected_queryset = [middle, bottom]
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Middle.objects.order_by("pk"), [repr(r) for r in expected_queryset], **transform_arg
)

expected_queryset = [bottom]
self.assertQuerysetEqual(
self.assertQuerySetEqual(
Bottom.objects.order_by("pk"), [repr(r) for r in expected_queryset], **transform_arg
)
2 changes: 1 addition & 1 deletion polymorphic/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_reset_polymorphic_ctype(self):

reset_polymorphic_ctype(Model2D, Model2B, Model2D, Model2A, Model2C)

self.assertQuerysetEqual(
self.assertQuerySetEqual(
Model2A.objects.order_by("pk"),
[Model2A, Model2D, Model2B, Model2B],
transform=lambda o: o.__class__,
Expand Down

0 comments on commit 63d291f

Please sign in to comment.