Ticket #18846: serializeMultitable.py

File serializeMultitable.py, 642 bytes (added by cheese, 12 years ago)

TestCase for the issue

Line 
1from django.core import serializers
2from django.test import TestCase
3from django.contrib.auth.models import User
4import json
5
6class Subuser(User):
7 pass
8
9class SerializeSubModelTest(TestCase):
10
11 def setUp(self):
12 Subuser.objects.create(username="sina")
13
14 def test_serializer(self):
15 object_list = Subuser.objects.all()
16 jsonstr = serializers.serialize('json', object_list, ensure_ascii=False)
17 print(jsonstr) # got '[{"pk": 1, "model": "tta.subuser", "fields": {"user_permissions": [], "groups": []}}]'
18 data = json.loads(jsonstr)
19 self.assertEqual('sina', data[0]['fields']['username'])
Back to Top