Skip to content

Commit

Permalink
Add an explicit order-by-PK test
Browse files Browse the repository at this point in the history
Refs #73.
  • Loading branch information
matthiask committed Jul 29, 2024
1 parent 81d342c commit c4faadd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __str__(self):


class UnorderedModel(TreeNode):
pass
name = models.CharField(max_length=100)


class StringOrderedModel(TreeNode):
Expand Down
15 changes: 15 additions & 0 deletions tests/testapp/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ def test_loops(self):
def test_unordered(self):
self.assertEqual(list(UnorderedModel.objects.all()), [])

u2 = UnorderedModel.objects.create(name="u2")
u1 = UnorderedModel.objects.create(name="u1")
u0 = UnorderedModel.objects.create(name="u0")

u1.parent = u0
u1.save()
u2.parent = u0
u2.save()

# Siblings are ordered by primary key (in order of creation)
self.assertSequenceEqual(
[obj.name for obj in UnorderedModel.objects.with_tree_fields()],
["u0", "u2", "u1"],
)

def test_revert(self):
tree = self.create_tree()
obj = (
Expand Down

0 comments on commit c4faadd

Please sign in to comment.