def test_rollback(self): TestT.create(subject_id=1) with start_transaction(TestT, TestA) as (test_t, test_a): test_t.create(subject_id=1) m = test_a.create(ep_num=1) qrset = [str(i) for i, in store.execute('select id from test_a order by id')] self.assertEqual(len(qrset), 0)
def run(t_ins, a_ins): with start_transaction(t_ins, a_ins) as (test_t_ins, test_a_ins): ret = test_a_ins.delete() if ret == 0: raise OrzForceRollBack test_t_ins.subject_id = 2 test_t_ins.save()
def test_basic(self): TestA.create(ep_num=1) TestA.gets_by(ep_num=1) TestA.count_by(ep_num=1) m = 0 before = TestA.create self.assertEqual(TestT.__transaction__, False) self.assertEqual(TestA.__transaction__, False) with start_transaction(TestT, TestA) as (test_t, test_a): zz = test_t.create(subject_id=1) m = test_a.create(ep_num=1) self.assertEqual(TestT.__transaction__, True) self.assertEqual(TestA.__transaction__, True) self.assertEqual(TestT.__transaction__, False) self.assertEqual(TestA.__transaction__, False) after = TestA.create self.assertEqual(before, after) self.assertTrue(zz.after_create) qrset = [ str(i) for i, in store.execute('select id from test_a order by id') ] self.assertEqual(qrset[-1], m.id) self.assertEqual(len(TestA.gets_by(ep_num=1)), 2) self.assertEqual(TestA.gets_by(ep_num=1)[0].id, m.id)
def test_basic(self): TestA.create(ep_num=1) TestA.gets_by(ep_num=1) TestA.count_by(ep_num=1) m = 0 before = TestA.create self.assertEqual(TestT.__transaction__, False) self.assertEqual(TestA.__transaction__, False) with start_transaction(TestT, TestA) as (test_t, test_a): zz = test_t.create(subject_id=1) m = test_a.create(ep_num=1) self.assertEqual(TestT.__transaction__, True) self.assertEqual(TestA.__transaction__, True) self.assertEqual(TestT.__transaction__, False) self.assertEqual(TestA.__transaction__, False) after = TestA.create self.assertEqual(before, after) self.assertTrue(zz.after_create) qrset = [str(i) for i, in store.execute('select id from test_a order by id')] self.assertEqual(qrset[-1], m.id) self.assertEqual(len(TestA.gets_by(ep_num=1)), 2) self.assertEqual(TestA.gets_by(ep_num=1)[0].id, m.id)
def test_rollback(self): TestT.create(subject_id=1) with start_transaction(TestT, TestA) as (test_t, test_a): test_t.create(subject_id=1) m = test_a.create(ep_num=1) qrset = [ str(i) for i, in store.execute('select id from test_a order by id') ] self.assertEqual(len(qrset), 0)
def run(t_ins, a_ins): with start_transaction(t_ins, a_ins) as (test_t_ins, test_a_ins): ret = test_a_ins.delete() if ret == 0: raise OrzForceRollBack test_t_ins.subject_id = 2 test_t_ins.save() self.assertEqual(t_ins.__transaction__, True) self.assertEqual(a_ins.__transaction__, True) self.assertEqual(t_ins.__transaction__, False) self.assertEqual(a_ins.__transaction__, False)