summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2025-01-07 10:01:40 -0500
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-01-08 10:20:48 +0100
commit7617d5be94a6e348d5ddf4644985b24235822034 (patch)
tree54d2a08951533a563018067d29ff3ca2f863f103
parentc068f000be7c486abb8b17fc565383679d7d4f82 (diff)
Refs #36065 -- Extracted composite primary key order by tests.
-rw-r--r--tests/composite_pk/test_filter.py24
-rw-r--r--tests/composite_pk/test_order_by.py57
2 files changed, 57 insertions, 24 deletions
diff --git a/tests/composite_pk/test_filter.py b/tests/composite_pk/test_filter.py
index 06cd6781df..864877483a 100644
--- a/tests/composite_pk/test_filter.py
+++ b/tests/composite_pk/test_filter.py
@@ -70,30 +70,6 @@ class CompositePKFilterTests(TestCase):
):
Comment.objects.filter(text__gt=expr).count()
- def test_order_comments_by_pk_asc(self):
- self.assertSequenceEqual(
- Comment.objects.order_by("pk"),
- (
- self.comment_1, # (1, 1)
- self.comment_2, # (1, 2)
- self.comment_3, # (1, 3)
- self.comment_5, # (1, 5)
- self.comment_4, # (2, 4)
- ),
- )
-
- def test_order_comments_by_pk_desc(self):
- self.assertSequenceEqual(
- Comment.objects.order_by("-pk"),
- (
- self.comment_4, # (2, 4)
- self.comment_5, # (1, 5)
- self.comment_3, # (1, 3)
- self.comment_2, # (1, 2)
- self.comment_1, # (1, 1)
- ),
- )
-
def test_filter_comments_by_pk_gt(self):
c11, c12, c13, c24, c15 = (
self.comment_1,
diff --git a/tests/composite_pk/test_order_by.py b/tests/composite_pk/test_order_by.py
new file mode 100644
index 0000000000..9d3dec58e7
--- /dev/null
+++ b/tests/composite_pk/test_order_by.py
@@ -0,0 +1,57 @@
+from django.test import TestCase
+
+from .models import Comment, Tenant, User
+
+
+class CompositePKOrderByTests(TestCase):
+ maxDiff = None
+
+ @classmethod
+ def setUpTestData(cls):
+ cls.tenant_1 = Tenant.objects.create()
+ cls.tenant_2 = Tenant.objects.create()
+ cls.tenant_3 = Tenant.objects.create()
+ cls.user_1 = User.objects.create(
+ tenant=cls.tenant_1,
+ id=1,
+ email="user0001@example.com",
+ )
+ cls.user_2 = User.objects.create(
+ tenant=cls.tenant_1,
+ id=2,
+ email="user0002@example.com",
+ )
+ cls.user_3 = User.objects.create(
+ tenant=cls.tenant_2,
+ id=3,
+ email="user0003@example.com",
+ )
+ cls.comment_1 = Comment.objects.create(id=1, user=cls.user_1)
+ cls.comment_2 = Comment.objects.create(id=2, user=cls.user_1)
+ cls.comment_3 = Comment.objects.create(id=3, user=cls.user_2)
+ cls.comment_4 = Comment.objects.create(id=4, user=cls.user_3)
+ cls.comment_5 = Comment.objects.create(id=5, user=cls.user_1)
+
+ def test_order_comments_by_pk_asc(self):
+ self.assertSequenceEqual(
+ Comment.objects.order_by("pk"),
+ (
+ self.comment_1, # (1, 1)
+ self.comment_2, # (1, 2)
+ self.comment_3, # (1, 3)
+ self.comment_5, # (1, 5)
+ self.comment_4, # (2, 4)
+ ),
+ )
+
+ def test_order_comments_by_pk_desc(self):
+ self.assertSequenceEqual(
+ Comment.objects.order_by("-pk"),
+ (
+ self.comment_4, # (2, 4)
+ self.comment_5, # (1, 5)
+ self.comment_3, # (1, 3)
+ self.comment_2, # (1, 2)
+ self.comment_1, # (1, 1)
+ ),
+ )