Skip to content

Commit f5e09b6

Browse files
committed
Add a unittest for the exact JSON format
1 parent e15a788 commit f5e09b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/testapp/test_data.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
2+
from unittest import skipIf
23

4+
import django
35
from django.db import models
46
from django.test import TransactionTestCase
57

@@ -644,3 +646,19 @@ def test_mti(self):
644646
{"model": "testapp.uniqueslugmti", "pk": t2.pk, "fields": {}},
645647
],
646648
)
649+
650+
@skipIf(
651+
django.VERSION > (6,),
652+
"Django changed the JSON dump format to include a final newline.",
653+
)
654+
def test_json_format(self):
655+
"""The exact format generated by dump_specs shouldn't change without us noticing"""
656+
657+
Tag.objects.create(name="Hello")
658+
specs = [*specs_for_models([Tag])]
659+
data = dump_specs(specs)
660+
661+
self.assertEqual(
662+
data,
663+
'{"version": 1, "specs": [{"model": "testapp.tag"}], "objects": [{"model": "testapp.tag", "pk": 5, "fields": {"name": "Hello", "parent": null}}]}',
664+
)

0 commit comments

Comments
 (0)