Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Oct 22, 2024
1 parent ba6147c commit b4f34ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
8 changes: 5 additions & 3 deletions tests/mongo_fields/test_embedded_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand Down
28 changes: 16 additions & 12 deletions tests/mongo_fields/test_listfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit b4f34ed

Please sign in to comment.