def test(self): mymodel = Mymodel() mysecond_model = Mymodel() mymodel.mymodel = mysecond_model json = JsonSerializer().serialize(mymodel) retrieved_mymodel = JsonUnSerializer().unserialize(json)
def testSerializationJson(self): historicData = HistoricData() historicData.annoDate = datetime.datetime(2013,5,22,10,30) json_str = JsonSerializer().serialize(historicData) print json_str uHistoricSpot = JsonUnSerializer().unserialize(json_str) self.assertEqual(uHistoricSpot.annoDate, datetime.datetime(2013,5,22,10,30))
def testSerializationFloat(self): model = ModelWithFloatField() model.float = 4.56 ajson = JsonSerializer().serialize(model) print ajson import simplejson as json dict = json.loads(ajson) self.assertEqual(dict['float'], 4.56)
def test_incorrect_minlength(self): toValidateListOfChilds = ToValidateListOfChilds() toValidateListOfChilds.name = "test" toValidateListOfChilds.childs = [ToValidateChild(childname="1")] try: toValidateListOfChilds.full_clean() self.fail("expected a object validation error") except ObjectValidationError: pass from django_documents.serializer import JsonSerializer print JsonSerializer().serialize(toValidateListOfChilds)
def testSerializationJson(self): data = Data() data.price = Decimal('12.555') data.full_clean() json_str = JsonSerializer().serialize(data) print json_str uDate = JsonUnSerializer().unserialize(json_str) self.assertEqual(uDate.price, Decimal('12.555')) print uDate.price
def testListStringIncorrectChoicesValidation(self): toValidateList = ToValidateList() toValidateList.language_codes = ['nl', "ce"] try: toValidateList.full_clean() self.fail("expected exception") except ObjectValidationError, ove: from django_documents.serializer import JsonSerializer print "Errors: %s" % ove print JsonSerializer().serialize(toValidateList) self.assertTrue('language_codes' in toValidateList._errors)
def test_multipleInheritance(self): registerdCar = RegisteredCar(type="test", name="mycar", licenceNumber="we-we-we") self.assertEqual("we-we-we", registerdCar.licenceNumber) self.assertEqual("test", registerdCar.type) ajson = JsonSerializer().serialize(registerdCar) unser_registerdCar = JsonUnSerializer().unserialize(ajson) self.assertEqual("we-we-we", unser_registerdCar.licenceNumber) self.assertEqual("test", unser_registerdCar.type)