52 self.cnx.transaction_actions, 'hop') |
52 self.cnx.transaction_actions, 'hop') |
53 self.assertRaises(NoSuchTransaction, |
53 self.assertRaises(NoSuchTransaction, |
54 self.cnx.undo_transaction, 'hop') |
54 self.cnx.undo_transaction, 'hop') |
55 txinfo = self.cnx.transaction_info(self.txuuid) |
55 txinfo = self.cnx.transaction_info(self.txuuid) |
56 self.failUnless(txinfo.datetime) |
56 self.failUnless(txinfo.datetime) |
57 self.assertEquals(txinfo.user_eid, self.session.user.eid) |
57 self.assertEqual(txinfo.user_eid, self.session.user.eid) |
58 self.assertEquals(txinfo.user().login, 'admin') |
58 self.assertEqual(txinfo.user().login, 'admin') |
59 actions = txinfo.actions_list() |
59 actions = txinfo.actions_list() |
60 self.assertEquals(len(actions), 2) |
60 self.assertEqual(len(actions), 2) |
61 actions = txinfo.actions_list(public=False) |
61 actions = txinfo.actions_list(public=False) |
62 self.assertEquals(len(actions), 6) |
62 self.assertEqual(len(actions), 6) |
63 a1 = actions[0] |
63 a1 = actions[0] |
64 self.assertEquals(a1.action, 'C') |
64 self.assertEqual(a1.action, 'C') |
65 self.assertEquals(a1.eid, self.toto.eid) |
65 self.assertEqual(a1.eid, self.toto.eid) |
66 self.assertEquals(a1.etype,'CWUser') |
66 self.assertEqual(a1.etype,'CWUser') |
67 self.assertEquals(a1.changes, None) |
67 self.assertEqual(a1.changes, None) |
68 self.assertEquals(a1.public, True) |
68 self.assertEqual(a1.public, True) |
69 self.assertEquals(a1.order, 1) |
69 self.assertEqual(a1.order, 1) |
70 a4 = actions[3] |
70 a4 = actions[3] |
71 self.assertEquals(a4.action, 'A') |
71 self.assertEqual(a4.action, 'A') |
72 self.assertEquals(a4.rtype, 'in_group') |
72 self.assertEqual(a4.rtype, 'in_group') |
73 self.assertEquals(a4.eid_from, self.toto.eid) |
73 self.assertEqual(a4.eid_from, self.toto.eid) |
74 self.assertEquals(a4.eid_to, self.toto.in_group[0].eid) |
74 self.assertEqual(a4.eid_to, self.toto.in_group[0].eid) |
75 self.assertEquals(a4.order, 4) |
75 self.assertEqual(a4.order, 4) |
76 for i, rtype in ((1, 'owned_by'), (2, 'owned_by'), |
76 for i, rtype in ((1, 'owned_by'), (2, 'owned_by'), |
77 (4, 'in_state'), (5, 'created_by')): |
77 (4, 'in_state'), (5, 'created_by')): |
78 a = actions[i] |
78 a = actions[i] |
79 self.assertEquals(a.action, 'A') |
79 self.assertEqual(a.action, 'A') |
80 self.assertEquals(a.eid_from, self.toto.eid) |
80 self.assertEqual(a.eid_from, self.toto.eid) |
81 self.assertEquals(a.rtype, rtype) |
81 self.assertEqual(a.rtype, rtype) |
82 self.assertEquals(a.order, i+1) |
82 self.assertEqual(a.order, i+1) |
83 # test undoable_transactions |
83 # test undoable_transactions |
84 txs = self.cnx.undoable_transactions() |
84 txs = self.cnx.undoable_transactions() |
85 self.assertEquals(len(txs), 1) |
85 self.assertEqual(len(txs), 1) |
86 self.assertEquals(txs[0].uuid, self.txuuid) |
86 self.assertEqual(txs[0].uuid, self.txuuid) |
87 # test transaction_info / undoable_transactions security |
87 # test transaction_info / undoable_transactions security |
88 cnx = self.login('anon') |
88 cnx = self.login('anon') |
89 self.assertRaises(NoSuchTransaction, |
89 self.assertRaises(NoSuchTransaction, |
90 cnx.transaction_info, self.txuuid) |
90 cnx.transaction_info, self.txuuid) |
91 self.assertRaises(NoSuchTransaction, |
91 self.assertRaises(NoSuchTransaction, |
92 cnx.transaction_actions, self.txuuid) |
92 cnx.transaction_actions, self.txuuid) |
93 self.assertRaises(NoSuchTransaction, |
93 self.assertRaises(NoSuchTransaction, |
94 cnx.undo_transaction, self.txuuid) |
94 cnx.undo_transaction, self.txuuid) |
95 txs = cnx.undoable_transactions() |
95 txs = cnx.undoable_transactions() |
96 self.assertEquals(len(txs), 0) |
96 self.assertEqual(len(txs), 0) |
97 |
97 |
98 def test_undoable_transactions(self): |
98 def test_undoable_transactions(self): |
99 toto = self.toto |
99 toto = self.toto |
100 e = self.session.create_entity('EmailAddress', |
100 e = self.session.create_entity('EmailAddress', |
101 address=u'toto@logilab.org', |
101 address=u'toto@logilab.org', |
103 txuuid1 = self.commit() |
103 txuuid1 = self.commit() |
104 toto.cw_delete() |
104 toto.cw_delete() |
105 txuuid2 = self.commit() |
105 txuuid2 = self.commit() |
106 undoable_transactions = self.cnx.undoable_transactions |
106 undoable_transactions = self.cnx.undoable_transactions |
107 txs = undoable_transactions(action='D') |
107 txs = undoable_transactions(action='D') |
108 self.assertEquals(len(txs), 1, txs) |
108 self.assertEqual(len(txs), 1, txs) |
109 self.assertEquals(txs[0].uuid, txuuid2) |
109 self.assertEqual(txs[0].uuid, txuuid2) |
110 txs = undoable_transactions(action='C') |
110 txs = undoable_transactions(action='C') |
111 self.assertEquals(len(txs), 2, txs) |
111 self.assertEqual(len(txs), 2, txs) |
112 self.assertEquals(txs[0].uuid, txuuid1) |
112 self.assertEqual(txs[0].uuid, txuuid1) |
113 self.assertEquals(txs[1].uuid, self.txuuid) |
113 self.assertEqual(txs[1].uuid, self.txuuid) |
114 txs = undoable_transactions(eid=toto.eid) |
114 txs = undoable_transactions(eid=toto.eid) |
115 self.assertEquals(len(txs), 3) |
115 self.assertEqual(len(txs), 3) |
116 self.assertEquals(txs[0].uuid, txuuid2) |
116 self.assertEqual(txs[0].uuid, txuuid2) |
117 self.assertEquals(txs[1].uuid, txuuid1) |
117 self.assertEqual(txs[1].uuid, txuuid1) |
118 self.assertEquals(txs[2].uuid, self.txuuid) |
118 self.assertEqual(txs[2].uuid, self.txuuid) |
119 txs = undoable_transactions(etype='CWUser') |
119 txs = undoable_transactions(etype='CWUser') |
120 self.assertEquals(len(txs), 2) |
120 self.assertEqual(len(txs), 2) |
121 txs = undoable_transactions(etype='CWUser', action='C') |
121 txs = undoable_transactions(etype='CWUser', action='C') |
122 self.assertEquals(len(txs), 1) |
122 self.assertEqual(len(txs), 1) |
123 self.assertEquals(txs[0].uuid, self.txuuid) |
123 self.assertEqual(txs[0].uuid, self.txuuid) |
124 txs = undoable_transactions(etype='EmailAddress', action='D') |
124 txs = undoable_transactions(etype='EmailAddress', action='D') |
125 self.assertEquals(len(txs), 0) |
125 self.assertEqual(len(txs), 0) |
126 txs = undoable_transactions(etype='EmailAddress', action='D', |
126 txs = undoable_transactions(etype='EmailAddress', action='D', |
127 public=False) |
127 public=False) |
128 self.assertEquals(len(txs), 1) |
128 self.assertEqual(len(txs), 1) |
129 self.assertEquals(txs[0].uuid, txuuid2) |
129 self.assertEqual(txs[0].uuid, txuuid2) |
130 txs = undoable_transactions(eid=toto.eid, action='R', public=False) |
130 txs = undoable_transactions(eid=toto.eid, action='R', public=False) |
131 self.assertEquals(len(txs), 1) |
131 self.assertEqual(len(txs), 1) |
132 self.assertEquals(txs[0].uuid, txuuid2) |
132 self.assertEqual(txs[0].uuid, txuuid2) |
133 |
133 |
134 def test_undo_deletion_base(self): |
134 def test_undo_deletion_base(self): |
135 toto = self.toto |
135 toto = self.toto |
136 e = self.session.create_entity('EmailAddress', |
136 e = self.session.create_entity('EmailAddress', |
137 address=u'toto@logilab.org', |
137 address=u'toto@logilab.org', |
141 pkey=u'ui.default-text-format', |
141 pkey=u'ui.default-text-format', |
142 value=u'text/rest', |
142 value=u'text/rest', |
143 for_user=toto) |
143 for_user=toto) |
144 self.commit() |
144 self.commit() |
145 txs = self.cnx.undoable_transactions() |
145 txs = self.cnx.undoable_transactions() |
146 self.assertEquals(len(txs), 2) |
146 self.assertEqual(len(txs), 2) |
147 toto.cw_delete() |
147 toto.cw_delete() |
148 txuuid = self.commit() |
148 txuuid = self.commit() |
149 actions = self.cnx.transaction_info(txuuid).actions_list() |
149 actions = self.cnx.transaction_info(txuuid).actions_list() |
150 self.assertEquals(len(actions), 1) |
150 self.assertEqual(len(actions), 1) |
151 toto.clear_all_caches() |
151 toto.clear_all_caches() |
152 e.clear_all_caches() |
152 e.clear_all_caches() |
153 errors = self.cnx.undo_transaction(txuuid) |
153 errors = self.cnx.undo_transaction(txuuid) |
154 undotxuuid = self.commit() |
154 undotxuuid = self.commit() |
155 self.assertEquals(undotxuuid, None) # undo not undoable |
155 self.assertEqual(undotxuuid, None) # undo not undoable |
156 self.assertEquals(errors, []) |
156 self.assertEqual(errors, []) |
157 self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': toto.eid})) |
157 self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': toto.eid})) |
158 self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': e.eid})) |
158 self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': e.eid})) |
159 self.failUnless(self.execute('Any X WHERE X has_text "toto@logilab"')) |
159 self.failUnless(self.execute('Any X WHERE X has_text "toto@logilab"')) |
160 self.assertEquals(toto.cw_adapt_to('IWorkflowable').state, 'activated') |
160 self.assertEqual(toto.cw_adapt_to('IWorkflowable').state, 'activated') |
161 self.assertEquals(toto.cw_adapt_to('IEmailable').get_email(), 'toto@logilab.org') |
161 self.assertEqual(toto.cw_adapt_to('IEmailable').get_email(), 'toto@logilab.org') |
162 self.assertEquals([(p.pkey, p.value) for p in toto.reverse_for_user], |
162 self.assertEqual([(p.pkey, p.value) for p in toto.reverse_for_user], |
163 [('ui.default-text-format', 'text/rest')]) |
163 [('ui.default-text-format', 'text/rest')]) |
164 self.assertEquals([g.name for g in toto.in_group], |
164 self.assertEqual([g.name for g in toto.in_group], |
165 ['users']) |
165 ['users']) |
166 self.assertEquals([et.name for et in toto.related('is', entities=True)], |
166 self.assertEqual([et.name for et in toto.related('is', entities=True)], |
167 ['CWUser']) |
167 ['CWUser']) |
168 self.assertEquals([et.name for et in toto.is_instance_of], |
168 self.assertEqual([et.name for et in toto.is_instance_of], |
169 ['CWUser']) |
169 ['CWUser']) |
170 # undoing shouldn't be visble in undoable transaction, and the undoed |
170 # undoing shouldn't be visble in undoable transaction, and the undoed |
171 # transaction should be removed |
171 # transaction should be removed |
172 txs = self.cnx.undoable_transactions() |
172 txs = self.cnx.undoable_transactions() |
173 self.assertEquals(len(txs), 2) |
173 self.assertEqual(len(txs), 2) |
174 self.assertRaises(NoSuchTransaction, |
174 self.assertRaises(NoSuchTransaction, |
175 self.cnx.transaction_info, txuuid) |
175 self.cnx.transaction_info, txuuid) |
176 self.check_transaction_deleted(txuuid) |
176 self.check_transaction_deleted(txuuid) |
177 # the final test: check we can login with the previously deleted user |
177 # the final test: check we can login with the previously deleted user |
178 self.login('toto') |
178 self.login('toto') |
207 self.toto.cw_delete() |
207 self.toto.cw_delete() |
208 txuuid = self.commit() |
208 txuuid = self.commit() |
209 g.cw_delete() |
209 g.cw_delete() |
210 self.commit() |
210 self.commit() |
211 errors = self.cnx.undo_transaction(txuuid) |
211 errors = self.cnx.undo_transaction(txuuid) |
212 self.assertEquals(errors, |
212 self.assertEqual(errors, |
213 [u"Can't restore relation in_group, object entity " |
213 [u"Can't restore relation in_group, object entity " |
214 "%s doesn't exist anymore." % g.eid]) |
214 "%s doesn't exist anymore." % g.eid]) |
215 ex = self.assertRaises(ValidationError, self.commit) |
215 ex = self.assertRaises(ValidationError, self.commit) |
216 self.assertEquals(ex.entity, self.toto.eid) |
216 self.assertEqual(ex.entity, self.toto.eid) |
217 self.assertEquals(ex.errors, |
217 self.assertEqual(ex.errors, |
218 {'in_group-subject': u'at least one relation in_group is ' |
218 {'in_group-subject': u'at least one relation in_group is ' |
219 'required on CWUser (%s)' % self.toto.eid}) |
219 'required on CWUser (%s)' % self.toto.eid}) |
220 |
220 |
221 def test_undo_creation_1(self): |
221 def test_undo_creation_1(self): |
222 session = self.session |
222 session = self.session |
265 session.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.toto.eid}) |
265 session.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.toto.eid}) |
266 self.toto.set_relations(in_group=g) |
266 self.toto.set_relations(in_group=g) |
267 self.commit() |
267 self.commit() |
268 ex = self.assertRaises(ValidationError, |
268 ex = self.assertRaises(ValidationError, |
269 self.cnx.undo_transaction, txuuid) |
269 self.cnx.undo_transaction, txuuid) |
270 self.assertEquals(ex.entity, g.eid) |
270 self.assertEqual(ex.entity, g.eid) |
271 self.assertEquals(ex.errors, |
271 self.assertEqual(ex.errors, |
272 {None: 'some later transaction(s) touch entity, undo them first'}) |
272 {None: 'some later transaction(s) touch entity, undo them first'}) |
273 # self.assertEquals(errors, |
273 # self.assertEqual(errors, |
274 # [u"Can't restore relation in_group, object entity " |
274 # [u"Can't restore relation in_group, object entity " |
275 # "%s doesn't exist anymore." % g.eid]) |
275 # "%s doesn't exist anymore." % g.eid]) |
276 # ex = self.assertRaises(ValidationError, self.commit) |
276 # ex = self.assertRaises(ValidationError, self.commit) |
277 # self.assertEquals(ex.entity, self.toto.eid) |
277 # self.assertEqual(ex.entity, self.toto.eid) |
278 # self.assertEquals(ex.errors, |
278 # self.assertEqual(ex.errors, |
279 # {'in_group-subject': u'at least one relation in_group is ' |
279 # {'in_group-subject': u'at least one relation in_group is ' |
280 # 'required on CWUser (%s)' % self.toto.eid}) |
280 # 'required on CWUser (%s)' % self.toto.eid}) |
281 |
281 |
282 # test implicit 'replacement' of an inlined relation |
282 # test implicit 'replacement' of an inlined relation |
283 |
283 |