def test_select(self): objs = TestPlan.db.select(Plan()) self.assertEqual(len(objs), 2) self.assertEqual(objs[0].getId(), 98) self.assertEqual(objs[0].getName(), 'plan name TD') self.assertEqual(objs[0].getCost(), 2.3) self.assertEqual(objs[0].getDesc(), 'plan desc TD') self.assertEqual(objs[1].getId(), 99) self.assertEqual(objs[1].getName(), 'plan name TD2') self.assertEqual(objs[1].getCost(), 2.4) self.assertEqual(objs[1].getDesc(), 'plan desc TD2') objs = TestPlan.db.select(Plan(98)) self.assertEqual(len(objs), 1) self.assertEqual(objs[0].getId(), 98) self.assertEqual(objs[0].getName(), 'plan name TD') self.assertEqual(objs[0].getCost(), 2.3) self.assertEqual(objs[0].getDesc(), 'plan desc TD') objs = TestPlan.db.select( Plan.createAdhoc({ 'name': 'plan name TD', 'cost': 2.3, 'desc': 'plan desc TD' })) self.assertEqual(len(objs), 1) self.assertEqual(objs[0].getId(), 98) self.assertEqual(objs[0].getName(), 'plan name TD') self.assertEqual(objs[0].getCost(), 2.3) self.assertEqual(objs[0].getDesc(), 'plan desc TD')
def test_insert(self): # Disable Foreign Keys checks for this test TestPlan.db.disableForeignKeys() with TestPlan.db.transaction() as t: TestPlan.db.upsert( Plan(100, 'plan name TD UPD', 5.6, 'plan desc TD UPD')) objs = TestPlan.db.select(Plan()) self.assertEqual(len(objs), 3) d = eval("{'id': 100}") for k, v in d.items(): self.assertEqual(objs[2].__getattribute__('get' + k.title())(), v) d = eval( "{'name': 'plan name TD UPD', 'cost': 5.6, 'desc': 'plan desc TD UPD'}" ) for k, v in d.items(): self.assertEqual(objs[2].__getattribute__('get' + k.title())(), v) # force a rollback t.fail()
def test_delete(self): # Disable Foreign Keys checks for this test TestPlan.db.disableForeignKeys() with TestPlan.db.transaction() as t: TestPlan.db.delete(Plan(98)) objs = TestPlan.db.select(Plan()) self.assertEqual(len(objs), 1) # force a rollback t.fail()
def test_create(self): obj = Plan.create((98, 'plan name TD', 2.3, 'plan desc TD')) self.assertEqual(obj.getId(), 98) self.assertEqual(obj.getName(), 'plan name TD') self.assertEqual(obj.getCost(), 2.3) self.assertEqual(obj.getDesc(), 'plan desc TD')
def test_update(self): # Disable Foreign Keys checks for this test TestPlan.db.disableForeignKeys() with TestPlan.db.transaction() as t: TestPlan.db.upsert( Plan(98, 'plan name TD UPD', 5.6, 'plan desc TD UPD')) objs = TestPlan.db.select(Plan(98)) self.assertEqual(len(objs), 1) self.assertEqual(objs[0].getId(), 98) d = eval( "{'name': 'plan name TD UPD', 'cost': 5.6, 'desc': 'plan desc TD UPD'}" ) for k, v in d.items(): self.assertEqual(objs[0].__getattribute__('get' + k.title())(), v) # force a rollback t.fail() with TestPlan.db.transaction() as t: plan = TestPlan.db.select(Plan(98))[0] for k, v in d.items(): plan.__getattribute__('set' + k.title())(v) TestPlan.db.upsert(plan) objs = TestPlan.db.select(Plan(98)) self.assertEqual(len(objs), 1) self.assertEqual(objs[0].getId(), 98) for k, v in d.items(): self.assertEqual(objs[0].__getattribute__('get' + k.title())(), v) # force a rollback t.fail()
def test_repr(self): obj = Plan(98, 'plan name TD', 2.3, 'plan desc TD') self.assertEqual( str(obj), "plan : Keys {'id': 98} : Values {'name': 'plan name TD', 'cost': 2.3, 'desc': 'plan desc TD'}" )
def test_keys_adhoc(self): l = Plan.createAdhoc(None) self.assertEqual(l.getTable(), 'plan') self.assertTrue(l._keys.getFields() is None)
def test_isNullable(self): obj = Plan() self.assertTrue(True and obj.isNullable('desc'))