1
0
mirror of https://github.com/rpkilby/jsonfield.git synced 2022-02-12 21:18:11 +03:00

Test serialize/deserialize

This commit is contained in:
Ryan P Kilby
2020-02-21 18:51:14 -08:00
parent c6e2b8e661
commit c3867f0d09

View File

@@ -155,6 +155,17 @@ class JSONFieldTest(TestCase):
pulled = self.json_model.objects.get(id=obj.pk)
self.assertEqual(obj.json, pulled.json)
def test_serialize_deserialize(self):
self.json_model.objects.create(json={'foo': 'bar'})
for f in ['python', 'json', 'xml']:
with self.subTest(format=f):
data = serialize(f, self.json_model.objects.all())
instance, = deserialize(f, data)
# The actual model instance is accessed as `object`.
self.assertEqual(instance.object.json, {'foo': 'bar'})
def test_default_parameters(self):
"""Test providing a default value to the model"""
model = JSONModel()