41 |
41 |
42 def check_transaction_deleted(self, txuuid): |
42 def check_transaction_deleted(self, txuuid): |
43 # also check transaction actions have been properly deleted |
43 # also check transaction actions have been properly deleted |
44 cu = self.session.system_sql( |
44 cu = self.session.system_sql( |
45 "SELECT * from tx_entity_actions WHERE tx_uuid='%s'" % txuuid) |
45 "SELECT * from tx_entity_actions WHERE tx_uuid='%s'" % txuuid) |
46 self.failIf(cu.fetchall()) |
46 self.assertFalse(cu.fetchall()) |
47 cu = self.session.system_sql( |
47 cu = self.session.system_sql( |
48 "SELECT * from tx_relation_actions WHERE tx_uuid='%s'" % txuuid) |
48 "SELECT * from tx_relation_actions WHERE tx_uuid='%s'" % txuuid) |
49 self.failIf(cu.fetchall()) |
49 self.assertFalse(cu.fetchall()) |
50 |
50 |
51 def test_undo_api(self): |
51 def test_undo_api(self): |
52 self.failUnless(self.txuuid) |
52 self.assertTrue(self.txuuid) |
53 # test transaction api |
53 # test transaction api |
54 self.assertRaises(NoSuchTransaction, |
54 self.assertRaises(NoSuchTransaction, |
55 self.cnx.transaction_info, 'hop') |
55 self.cnx.transaction_info, 'hop') |
56 self.assertRaises(NoSuchTransaction, |
56 self.assertRaises(NoSuchTransaction, |
57 self.cnx.transaction_actions, 'hop') |
57 self.cnx.transaction_actions, 'hop') |
58 self.assertRaises(NoSuchTransaction, |
58 self.assertRaises(NoSuchTransaction, |
59 self.cnx.undo_transaction, 'hop') |
59 self.cnx.undo_transaction, 'hop') |
60 txinfo = self.cnx.transaction_info(self.txuuid) |
60 txinfo = self.cnx.transaction_info(self.txuuid) |
61 self.failUnless(txinfo.datetime) |
61 self.assertTrue(txinfo.datetime) |
62 self.assertEqual(txinfo.user_eid, self.session.user.eid) |
62 self.assertEqual(txinfo.user_eid, self.session.user.eid) |
63 self.assertEqual(txinfo.user().login, 'admin') |
63 self.assertEqual(txinfo.user().login, 'admin') |
64 actions = txinfo.actions_list() |
64 actions = txinfo.actions_list() |
65 self.assertEqual(len(actions), 2) |
65 self.assertEqual(len(actions), 2) |
66 actions = txinfo.actions_list(public=False) |
66 actions = txinfo.actions_list(public=False) |
157 e.cw_clear_all_caches() |
157 e.cw_clear_all_caches() |
158 errors = self.cnx.undo_transaction(txuuid) |
158 errors = self.cnx.undo_transaction(txuuid) |
159 undotxuuid = self.commit() |
159 undotxuuid = self.commit() |
160 self.assertEqual(undotxuuid, None) # undo not undoable |
160 self.assertEqual(undotxuuid, None) # undo not undoable |
161 self.assertEqual(errors, []) |
161 self.assertEqual(errors, []) |
162 self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': toto.eid})) |
162 self.assertTrue(self.execute('Any X WHERE X eid %(x)s', {'x': toto.eid})) |
163 self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': e.eid})) |
163 self.assertTrue(self.execute('Any X WHERE X eid %(x)s', {'x': e.eid})) |
164 self.failUnless(self.execute('Any X WHERE X has_text "toto@logilab"')) |
164 self.assertTrue(self.execute('Any X WHERE X has_text "toto@logilab"')) |
165 self.assertEqual(toto.cw_adapt_to('IWorkflowable').state, 'activated') |
165 self.assertEqual(toto.cw_adapt_to('IWorkflowable').state, 'activated') |
166 self.assertEqual(toto.cw_adapt_to('IEmailable').get_email(), 'toto@logilab.org') |
166 self.assertEqual(toto.cw_adapt_to('IEmailable').get_email(), 'toto@logilab.org') |
167 self.assertEqual([(p.pkey, p.value) for p in toto.reverse_for_user], |
167 self.assertEqual([(p.pkey, p.value) for p in toto.reverse_for_user], |
168 [('ui.default-text-format', 'text/rest')]) |
168 [('ui.default-text-format', 'text/rest')]) |
169 self.assertEqual([g.name for g in toto.in_group], |
169 self.assertEqual([g.name for g in toto.in_group], |
229 c = session.create_entity('Card', title=u'hop', content=u'hop') |
229 c = session.create_entity('Card', title=u'hop', content=u'hop') |
230 p = session.create_entity('Personne', nom=u'louis', fiche=c) |
230 p = session.create_entity('Personne', nom=u'louis', fiche=c) |
231 txuuid = self.commit() |
231 txuuid = self.commit() |
232 errors = self.cnx.undo_transaction(txuuid) |
232 errors = self.cnx.undo_transaction(txuuid) |
233 self.commit() |
233 self.commit() |
234 self.failIf(errors) |
234 self.assertFalse(errors) |
235 self.failIf(self.execute('Any X WHERE X eid %(x)s', {'x': c.eid})) |
235 self.assertFalse(self.execute('Any X WHERE X eid %(x)s', {'x': c.eid})) |
236 self.failIf(self.execute('Any X WHERE X eid %(x)s', {'x': p.eid})) |
236 self.assertFalse(self.execute('Any X WHERE X eid %(x)s', {'x': p.eid})) |
237 self.failIf(self.execute('Any X,Y WHERE X fiche Y')) |
237 self.assertFalse(self.execute('Any X,Y WHERE X fiche Y')) |
238 self.session.set_cnxset() |
238 self.session.set_cnxset() |
239 for eid in (p.eid, c.eid): |
239 for eid in (p.eid, c.eid): |
240 self.failIf(session.system_sql( |
240 self.assertFalse(session.system_sql( |
241 'SELECT * FROM entities WHERE eid=%s' % eid).fetchall()) |
241 'SELECT * FROM entities WHERE eid=%s' % eid).fetchall()) |
242 self.failIf(session.system_sql( |
242 self.assertFalse(session.system_sql( |
243 'SELECT 1 FROM owned_by_relation WHERE eid_from=%s' % eid).fetchall()) |
243 'SELECT 1 FROM owned_by_relation WHERE eid_from=%s' % eid).fetchall()) |
244 # added by sql in hooks (except when using dataimport) |
244 # added by sql in hooks (except when using dataimport) |
245 self.failIf(session.system_sql( |
245 self.assertFalse(session.system_sql( |
246 'SELECT 1 FROM is_relation WHERE eid_from=%s' % eid).fetchall()) |
246 'SELECT 1 FROM is_relation WHERE eid_from=%s' % eid).fetchall()) |
247 self.failIf(session.system_sql( |
247 self.assertFalse(session.system_sql( |
248 'SELECT 1 FROM is_instance_of_relation WHERE eid_from=%s' % eid).fetchall()) |
248 'SELECT 1 FROM is_instance_of_relation WHERE eid_from=%s' % eid).fetchall()) |
249 self.check_transaction_deleted(txuuid) |
249 self.check_transaction_deleted(txuuid) |
250 |
250 |
251 |
251 |
252 def test_undo_creation_integrity_1(self): |
252 def test_undo_creation_integrity_1(self): |