summaryrefslogtreecommitdiff
path: root/tests/serializers/test_natural.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/serializers/test_natural.py')
-rw-r--r--tests/serializers/test_natural.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/serializers/test_natural.py b/tests/serializers/test_natural.py
index b405dc3e28..4dff100cc7 100644
--- a/tests/serializers/test_natural.py
+++ b/tests/serializers/test_natural.py
@@ -1,5 +1,7 @@
+from unittest import mock
+
from django.core import serializers
-from django.db import connection
+from django.db import connection, models
from django.test import TestCase
from .models import (
@@ -336,6 +338,20 @@ def nullable_natural_key_m2m_test(self, format):
)
+def natural_key_m2m_totally_ordered_test(self, format):
+ t1 = NaturalKeyThing.objects.create(key="t1")
+ t2 = NaturalKeyThing.objects.create(key="t2")
+ t3 = NaturalKeyThing.objects.create(key="t3")
+ t1.other_things.add(t2, t3)
+
+ with mock.patch.object(models.QuerySet, "order_by") as mock_order_by:
+ serializers.serialize(format, [t1], use_natural_foreign_keys=True)
+ mock_order_by.assert_called_once_with("pk")
+ mock_order_by.reset_mock()
+ serializers.serialize(format, [t1], use_natural_foreign_keys=False)
+ mock_order_by.assert_called_once_with("pk")
+
+
# Dynamically register tests for each serializer
register_tests(
NaturalKeySerializerTests,
@@ -385,3 +401,8 @@ register_tests(
"test_%s_nullable_natural_key_m2m",
nullable_natural_key_m2m_test,
)
+register_tests(
+ NaturalKeySerializerTests,
+ "test_%s_natural_key_m2m_totally_ordered",
+ natural_key_m2m_totally_ordered_test,
+)