From b4f34edb6c28a34be9fc991ab3cb72d74961f74f Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 21 Oct 2024 20:11:05 -0400 Subject: [PATCH] edits --- tests/mongo_fields/test_embedded_model.py | 8 ++++--- tests/mongo_fields/test_listfield.py | 28 +++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/mongo_fields/test_embedded_model.py b/tests/mongo_fields/test_embedded_model.py index bd2de63163..43d48db5b9 100644 --- a/tests/mongo_fields/test_embedded_model.py +++ b/tests/mongo_fields/test_embedded_model.py @@ -117,7 +117,9 @@ def test_typed_listfield(self): ) obj = EmbeddedModelFieldModel.objects.get() # self.assertIn(5, obj.typed_list[1].setfield) - self.assertEqual([target.index for target in obj.ordered_list], range(1, 6)) + self.assertEqual( + [target.index for target in obj.ordered_list], list(range(1, 6)) + ) def test_untyped_listfield(self): EmbeddedModelFieldModel.objects.create( @@ -133,7 +135,7 @@ def test_untyped_listfield(self): ): self.assertIsInstance(instance, cls) self.assertNotEqual(instances[0].auto_now, None) - self.assertEqual(instances[1].ordered_ints, range(1, 6)) + self.assertEqual(instances[1].ordered_ints, list(range(1, 6))) def _test_untyped_dict(self): EmbeddedModelFieldModel.objects.create( @@ -147,7 +149,7 @@ def _test_untyped_dict(self): # self.assertIsInstance(data["a"], SetModel) # self.assertNotEqual(data["c"].auto_now["y"], None) - def test_foreignkey_in_embedded_object(self): + def test_foreign_key_in_embedded_object(self): simple = EmbeddedModel(some_relation=Target.objects.create(index=1)) obj = EmbeddedModelFieldModel.objects.create(simple=simple) simple = EmbeddedModelFieldModel.objects.get().simple diff --git a/tests/mongo_fields/test_listfield.py b/tests/mongo_fields/test_listfield.py index d450bdbc3b..090f65cf7f 100644 --- a/tests/mongo_fields/test_listfield.py +++ b/tests/mongo_fields/test_listfield.py @@ -22,8 +22,12 @@ class IterableFieldsTests(TestCase): unordered_ints = [4, 2, 6, 1] def setUp(self): - for i, float in zip(range(1, 5), self.floats): - ListModel(integer=i, floating_point=float, names=self.names[:i]).save() + self.objs = [ + ListModel.objects.create( + integer=i, floating_point=self.floats[i], names=self.names[: i + 1] + ) + for i in range(4) + ] def test_startswith(self): self.assertEqual( @@ -86,7 +90,7 @@ def test_gt(self): dict( [ (entity.pk, entity.names) - for entity in ListModel.objects.filter(names__gt="Kakashi") + for entity in ListModel.objects.filter(names__gt=["Naruto"]) ] ), dict( @@ -151,17 +155,15 @@ def test_lte(self): ) def test_equals(self): - self.assertEqual( - [entity.names for entity in ListModel.objects.filter(names="Sakura")], - [["Kakashi", "Naruto", "Sasuke", "Sakura"]], + self.assertQuerySetEqual( + ListModel.objects.filter(names=["Kakashi"]), + [self.objs[0]], ) # Test with additonal pk filter (for DBs that have special pk # queries). - query = ListModel.objects.filter(names="Sakura") - self.assertEqual( - query.get(pk=query[0].pk).names, ["Kakashi", "Naruto", "Sasuke", "Sakura"] - ) + query = ListModel.objects.filter(names=["Kakashi"]) + self.assertEqual(query.get(pk=query[0].pk).names, ["Kakashi"]) def test_is_null(self): self.assertEqual(ListModel.objects.filter(names__isnull=True).count(), 0) @@ -231,13 +233,15 @@ def test_Q_objects(self): [["Kakashi", "Naruto", "Sasuke", "Sakura"]], ) - def test_list_with_foreignkeys(self): + def test_list_with_foreign_keys(self): model1 = Model.objects.create() model2 = Model.objects.create() ReferenceList.objects.create(keys=[model1.pk, model2.pk]) self.assertEqual(ReferenceList.objects.get().keys[0], model1.pk) - self.assertEqual(ReferenceList.objects.filter(keys=model1.pk).count(), 1) + self.assertEqual( + ReferenceList.objects.filter(keys=[model1.pk, model2.pk]).count(), 1 + ) def test_list_with_foreign_conversion(self): decimal = DecimalKey.objects.create(decimal=Decimal("1.5"))