Ticket #4714: json_serializer_should_deal_with_None_primary_keys.py

File json_serializer_should_deal_with_None_primary_keys.py, 997 bytes (added by phil.h.smith@…, 17 years ago)

reproducing unit test

Line 
1from django.core.serializers import serialize, deserialize
2from mysite.polls.models import Poll
3from datetime import datetime
4
5from django.core.validators import ValidationError
6
7from unittest import TestCase
8
9class JsonSerializerShouldDealWithNonePrimaryKeysTest(TestCase):
10 def testAlreadyHandlesNonNullPKs(self):
11 m = self.model()
12 m.save()
13
14 try:
15 list(deserialize('json', serialize('json', [m])))[0].object
16 except ValidationError:
17 self.fail()
18
19 def testBlowsUpBecauseNoneInAStringIsNotNull(self):
20 m = self.model()
21 # no save.
22
23 serialized = serialize('json', [m])
24 self.assertFalse('null' in serialized)
25 self.assertTrue('"None"' in serialized)
26
27 try:
28 list(deserialize('json', serialized))[0].object
29 self.fail()
30 except ValidationError, va:
31 self.assertEquals(['This value must be an integer.'], va.messages)
32
33 def model(self):
34 return Poll(question="What's up?", pub_date=datetime.now())
Back to Top