def test_date(self): fun = FunModel(date=datetime(2005,1,2,13)) def do_to_d(df): return fun.to_d(dateformat=df)['dt'] self.assertEqual(fun.date, datetime(2005,1,2,13)) self.assertEqual(do_to_d('datetime'), datetime(2005,1,2,13)) fun.date = [2005,1,2,16] self.assertEqual(fun.date, datetime(2005,1,2,16)) self.assertEqual(do_to_d('list'),(2005,1,2,16,0,0)) fun.date = 1104660000 self.assertEqual(fun.date, datetime(2005,1,2,10)) self.assertEqual(do_to_d('epoch'),1104660000)
def test_merge(self): f = FunModel(_id='7',enum='red') f.save() g = FunModel(_id='7',dic={'three':4}) g.merge() ob = FunModel.get_id('7').to_d() del ob['ca'] ob.pop('_rev',None) self.failUnlessEqual(ob, dict(_id='7', e='red', d={'three':4}))
def test_fun_model(self): fun = FunModel() fun.part = PersonModel() self.assertRaises(TypeError, setattr, fun, 'enum', 'green') self.assertRaises(ValueError, setattr, fun, 'real', 'i') self.assertRaises(TypeError, setattr, fun, 'dic', [2,3]) self.assertRaises(TypeError, setattr, fun, 'created', []) self.assertRaises(TypeError, setattr, fun, 'names', [7,8]) self.assertRaises(TypeError, setattr, fun, 'names', 13) self.assertEqual(fun.enum, None) self.assertEqual(fun.part.age, 7) fun.part.age=100 self.assertEqual(fun.part.age, 100) fun.part = {'n':'jeff'} self.assertEqual(fun.part.age, 7) self.assertEqual(fun.part.name, 'jeff')
def test_fun_model(self): dic = {"one":2, 'three':"four", 'five':["six",7]} names = ['Shenzi', 'Banzai', 'ed'] now = datetime.datetime.utcnow() fun = FunModel( _id="fun", enum="red", real=3.14, dic=dic, names=names, ) fun.part=PersonModel(name="scar", age=32) fun.save() fun = FunModel.get_id("fun") self.failUnlessEqual( fun.enum, 'red') self.failUnlessEqual( fun.real, 3.14) self.failUnlessEqual( fun.dic, dic) dt = abs(fun.created-now) self.failUnless( dt.days==0 and dt.seconds==0 ) self.failUnlessEqual( fun.names, names) self.failUnlessEqual( fun.part.name, "scar") self.failUnlessEqual( fun.part.age, 32)