[SQL-CVS] SQLObject/tests test.py,1.26,1.27
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <ian...@us...> - 2003-09-07 22:35:16
|
Update of /cvsroot/sqlobject/SQLObject/tests In directory sc8-pr-cvs1:/tmp/cvs-serv5224/tests Modified Files: test.py Log Message: Added conversion/validation to columns Index: test.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/tests/test.py,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** test.py 7 Sep 2003 19:14:07 -0000 1.26 --- test.py 7 Sep 2003 22:35:09 -0000 1.27 *************** *** 18,21 **** --- 18,22 ---- from SQLObjectTest import * from SQLObject import * + from SQLObject.include import Validator from mx import DateTime *************** *** 623,626 **** --- 624,665 ---- b.sync() self.assertEqual(b.name, 'bobby') + + ######################################## + ## Validation/conversion + ######################################## + + class SOValidation(SQLObject): + + name = StringCol(validator=Validator.PlainText(), default='x') + name2 = StringCol(validator=Validator.ConfirmType(str), default='y') + name3 = StringCol(validator=Validator.Wrapper(toPython=int), default=100) + + class ValidationTest(SQLObjectTest): + + classes = [SOValidation] + + def testValidate(self): + t = SOValidation.new(name='hey') + self.assertRaises(Validator.InvalidField, setattr, t, + 'name', '!!!') + t.name = 'you' + + def testConfirmType(self): + t = SOValidation.new(name2='hey') + self.assertRaises(Validator.InvalidField, setattr, t, + 'name2', 1) + t.name2 = 'you' + + def testWrapType(self): + t = SOValidation.new(name3=1) + self.assertRaises(Validator.InvalidField, setattr, t, + 'name3', 'x') + t.name3 = 1L + self.assertEqual(t.name3, 1) + t.name3 = '1' + self.assertEqual(t.name3, 1) + t.name3 = 0 + self.assertEqual(t.name3, 0) + ######################################## |