diff --git a/polymorphic/tests/__init__.py b/polymorphic/tests/__init__.py index e69de29b..3d112022 100644 --- a/polymorphic/tests/__init__.py +++ b/polymorphic/tests/__init__.py @@ -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 diff --git a/polymorphic/tests/test_multidb.py b/polymorphic/tests/test_multidb.py index 716b3f96..192bb778 100644 --- a/polymorphic/tests/test_multidb.py +++ b/polymorphic/tests/test_multidb.py @@ -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__, @@ -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) ), diff --git a/polymorphic/tests/test_orm.py b/polymorphic/tests/test_orm.py index 3c38f202..61f7d242 100644 --- a/polymorphic/tests/test_orm.py +++ b/polymorphic/tests/test_orm.py @@ -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__, @@ -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__, @@ -336,7 +336,7 @@ 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__, @@ -344,7 +344,7 @@ def test_get_real_instances(self): # 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__, @@ -352,7 +352,7 @@ def test_get_real_instances(self): # 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") @@ -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 ) @@ -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__, @@ -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 ) @@ -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") @@ -556,7 +556,7 @@ 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__, @@ -564,7 +564,7 @@ def test_instance_of_filter(self): ) objects = Model2A.objects.filter(instance_of=Model2B) - self.assertQuerysetEqual( + self.assertQuerySetEqual( objects, [Model2B, Model2C, Model2D], transform=lambda o: o.__class__, @@ -572,7 +572,7 @@ def test_instance_of_filter(self): ) objects = Model2A.objects.filter(Q(instance_of=Model2B)) - self.assertQuerysetEqual( + self.assertQuerySetEqual( objects, [Model2B, Model2C, Model2D], transform=lambda o: o.__class__, @@ -580,7 +580,7 @@ def test_instance_of_filter(self): ) objects = Model2A.objects.not_instance_of(Model2B) - self.assertQuerysetEqual( + self.assertQuerySetEqual( objects, [Model2A], transform=lambda o: o.__class__, ordered=False ) @@ -588,7 +588,7 @@ 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 ) @@ -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 ) @@ -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__, @@ -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), @@ -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"), @@ -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), diff --git a/polymorphic/tests/test_regression.py b/polymorphic/tests/test_regression.py index e416f4fb..0f48971e 100644 --- a/polymorphic/tests/test_regression.py +++ b/polymorphic/tests/test_regression.py @@ -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 ) diff --git a/polymorphic/tests/test_utils.py b/polymorphic/tests/test_utils.py index 1495ea02..0934a507 100644 --- a/polymorphic/tests/test_utils.py +++ b/polymorphic/tests/test_utils.py @@ -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__,