summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2015-04-01 15:42:09 -0400
committerSimon Charette <charette.s@gmail.com>2015-04-02 15:21:43 -0400
commit5bc3123479bd97dc9d8a36fa9a3421a71063d1da (patch)
treeefe8d154cb1487c318b436f6f5813863e6b042b4 /tests
parent147ac856131233b2960503c3cc0d65059a57851a (diff)
Fixed #24558 -- Made dumpdata mapping ordering deterministic.
Thanks to gfairchild for the report and Claude for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/serializers/tests.py45
-rw-r--r--tests/timezones/tests.py2
2 files changed, 46 insertions, 1 deletions
diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py
index 5448b01b29..1d0a0bead5 100644
--- a/tests/serializers/tests.py
+++ b/tests/serializers/tests.py
@@ -266,6 +266,17 @@ class SerializersTestBase(object):
obj.save()
self.assertEqual(Category.objects.all().count(), 5)
+ def test_deterministic_mapping_ordering(self):
+ """Mapping such as fields should be deterministically ordered. (#24558)"""
+ output = serializers.serialize(self.serializer_name, [self.a1], indent=2)
+ categories = self.a1.categories.values_list('pk', flat=True)
+ self.assertEqual(output, self.mapping_ordering_str % {
+ 'article_pk': self.a1.pk,
+ 'author_pk': self.a1.author_id,
+ 'first_category_pk': categories[0],
+ 'second_category_pk': categories[1],
+ })
+
class SerializersTransactionTestBase(object):
@@ -303,6 +314,15 @@ class XmlSerializerTestCase(SerializersTestBase, TestCase):
<field type="CharField" name="name">Non-fiction</field>
</object>
</django-objects>"""
+ mapping_ordering_str = """<?xml version="1.0" encoding="utf-8"?>
+<django-objects version="1.0">
+ <object model="serializers.article" pk="%(article_pk)s">
+ <field name="author" rel="ManyToOneRel" to="serializers.author">%(author_pk)s</field>
+ <field name="headline" type="CharField">Poker has no place on ESPN</field>
+ <field name="pub_date" type="DateTimeField">2006-06-16T11:00:00</field>
+ <field name="categories" rel="ManyToManyRel" to="serializers.category"><object pk="%(first_category_pk)s"></object><object pk="%(second_category_pk)s"></object></field>
+ </object>
+</django-objects>"""
@staticmethod
def _comparison_value(value):
@@ -373,6 +393,22 @@ class JsonSerializerTestCase(SerializersTestBase, TestCase):
"model": "serializers.category",
"fields": {"name": "Non-fiction"}
}]"""
+ mapping_ordering_str = """[
+{
+ "model": "serializers.article",
+ "pk": %(article_pk)s,
+ "fields": {
+ "author": %(author_pk)s,
+ "headline": "Poker has no place on ESPN",
+ "pub_date": "2006-06-16T11:00:00",
+ "categories": [
+ %(first_category_pk)s,
+ %(second_category_pk)s
+ ]
+ }
+}
+]
+"""
@staticmethod
def _validate_output(serial_str):
@@ -533,6 +569,15 @@ class YamlSerializerTestCase(SerializersTestBase, TestCase):
name: Non-fiction
model: serializers.category"""
+ mapping_ordering_str = """- model: serializers.article
+ pk: %(article_pk)s
+ fields:
+ author: %(author_pk)s
+ headline: Poker has no place on ESPN
+ pub_date: 2006-06-16 11:00:00
+ categories: [%(first_category_pk)s, %(second_category_pk)s]
+"""
+
@staticmethod
def _validate_output(serial_str):
try:
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index d623492f68..d87e2d2566 100644
--- a/tests/timezones/tests.py
+++ b/tests/timezones/tests.py
@@ -594,7 +594,7 @@ class SerializationTests(TestCase):
def assert_yaml_contains_datetime(self, yaml, dt):
# Depending on the yaml dumper, '!timestamp' might be absent
six.assertRegex(self, yaml,
- r"- fields: {dt: !(!timestamp)? '%s'}" % re.escape(dt))
+ r"\n fields: {dt: !(!timestamp)? '%s'}" % re.escape(dt))
def test_naive_datetime(self):
dt = datetime.datetime(2011, 9, 1, 13, 20, 30)