author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Fri, 13 Jun 2014 12:07:51 +0200 | |
changeset 10352 | bab2befaac9b |
parent 10260 | 0e61be7bff10 |
child 10365 | 21461f80f348 |
permissions | -rw-r--r-- |
7530
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
2 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5104
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
19 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
20 |
from cubicweb import ValidationError |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
21 |
from cubicweb.devtools.testlib import CubicWebTC |
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
22 |
import cubicweb.server.session |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8812
diff
changeset
|
23 |
from cubicweb.server.session import Connection as OldConnection |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
24 |
|
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
25 |
from cubicweb.server.sources.native import UndoTransactionException, _UndoException |
7530
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
26 |
|
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
27 |
from cubicweb.transaction import NoSuchTransaction |
7530
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
28 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
29 |
class UndoableTransactionTC(CubicWebTC): |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
30 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
31 |
def setup_database(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
32 |
with self.admin_access.repo_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
33 |
self.totoeid = self.create_user(cnx, 'toto', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
34 |
password='toto', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
35 |
groups=('users',), |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
36 |
commit=False).eid |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
37 |
self.txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
38 |
|
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
39 |
def toto(self, cnx): |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
40 |
return cnx.entity_from_eid(self.totoeid) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
41 |
|
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
42 |
def setUp(self): |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8812
diff
changeset
|
43 |
class Connection(OldConnection): |
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
44 |
"""Force undo feature to be turned on in all case""" |
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
45 |
undo_actions = property(lambda tx: True, lambda x, y:None) |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8812
diff
changeset
|
46 |
cubicweb.server.session.Connection = Connection |
8812
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
47 |
super(UndoableTransactionTC, self).setUp() |
52af67a2f0a5
[session/transaction] move most undo support into transaction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8695
diff
changeset
|
48 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
49 |
def tearDown(self): |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8812
diff
changeset
|
50 |
cubicweb.server.session.Connection = OldConnection |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
51 |
super(UndoableTransactionTC, self).tearDown() |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
52 |
|
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
53 |
def check_transaction_deleted(self, cnx, txuuid): |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
54 |
# also check transaction actions have been properly deleted |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
55 |
cu = cnx.system_sql( |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
56 |
"SELECT * from tx_entity_actions WHERE tx_uuid='%s'" % txuuid) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
57 |
self.assertFalse(cu.fetchall()) |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
58 |
cu = cnx.system_sql( |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
59 |
"SELECT * from tx_relation_actions WHERE tx_uuid='%s'" % txuuid) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
60 |
self.assertFalse(cu.fetchall()) |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
61 |
|
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
62 |
def assertUndoTransaction(self, cnx, txuuid, expected_errors=None): |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
63 |
if expected_errors is None : |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
64 |
expected_errors = [] |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
65 |
try: |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
66 |
cnx.undo_transaction(txuuid) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
67 |
except UndoTransactionException as exn: |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
68 |
errors = exn.errors |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
69 |
else: |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
70 |
errors = [] |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
71 |
self.assertEqual(errors, expected_errors) |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
72 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
73 |
def test_undo_api(self): |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
74 |
self.assertTrue(self.txuuid) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
75 |
# test transaction api |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
76 |
with self.admin_access.client_cnx() as cnx: |
9996
65bb21409292
[server] hold connection to the db in tx_actions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
77 |
tx_actions = cnx.transaction_actions(self.txuuid) |
65bb21409292
[server] hold connection to the db in tx_actions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
78 |
self.assertEqual(len(tx_actions), 2, tx_actions) |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
79 |
self.assertRaises(NoSuchTransaction, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
80 |
cnx.transaction_info, 'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
81 |
self.assertRaises(NoSuchTransaction, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
82 |
cnx.transaction_actions, 'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
83 |
self.assertRaises(NoSuchTransaction, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
84 |
cnx.undo_transaction, 'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
85 |
txinfo = cnx.transaction_info(self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
86 |
self.assertTrue(txinfo.datetime) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
87 |
self.assertEqual(txinfo.user_eid, cnx.user.eid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
88 |
self.assertEqual(txinfo.user().login, 'admin') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
89 |
actions = txinfo.actions_list() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
90 |
self.assertEqual(len(actions), 2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
91 |
actions = txinfo.actions_list(public=False) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
92 |
self.assertEqual(len(actions), 6) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
93 |
a1 = actions[0] |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
94 |
self.assertEqual(a1.action, 'C') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
95 |
self.assertEqual(a1.eid, self.totoeid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
96 |
self.assertEqual(a1.etype,'CWUser') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
97 |
self.assertEqual(a1.ertype, 'CWUser') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
98 |
self.assertEqual(a1.changes, None) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
99 |
self.assertEqual(a1.public, True) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
100 |
self.assertEqual(a1.order, 1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
101 |
a4 = actions[3] |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
102 |
self.assertEqual(a4.action, 'A') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
103 |
self.assertEqual(a4.rtype, 'in_group') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
104 |
self.assertEqual(a4.ertype, 'in_group') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
105 |
self.assertEqual(a4.eid_from, self.totoeid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
106 |
self.assertEqual(a4.eid_to, self.toto(cnx).in_group[0].eid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
107 |
self.assertEqual(a4.order, 4) |
9948
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
108 |
for i, rtype in ((1, 'owned_by'), (2, 'owned_by')): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
109 |
a = actions[i] |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
110 |
self.assertEqual(a.action, 'A') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
111 |
self.assertEqual(a.eid_from, self.totoeid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
112 |
self.assertEqual(a.rtype, rtype) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
113 |
self.assertEqual(a.order, i+1) |
9948
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
114 |
self.assertEqual(set((actions[4].rtype, actions[5].rtype)), |
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
115 |
set(('in_state', 'created_by'))) |
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
116 |
for i in (4, 5): |
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
117 |
a = actions[i] |
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
118 |
self.assertEqual(a.action, 'A') |
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
119 |
self.assertEqual(a.eid_from, self.totoeid) |
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
120 |
self.assertEqual(a.order, i+1) |
798ab1216523
[test] Make test_undo_api less random
Julien Cristau <julien.cristau@logilab.fr>
parents:
9786
diff
changeset
|
121 |
|
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
122 |
# test undoable_transactions |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
123 |
txs = cnx.undoable_transactions() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
124 |
self.assertEqual(len(txs), 1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
125 |
self.assertEqual(txs[0].uuid, self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
126 |
# test transaction_info / undoable_transactions security |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
127 |
with self.new_access('anon').client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
128 |
self.assertRaises(NoSuchTransaction, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
129 |
cnx.transaction_info, self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
130 |
self.assertRaises(NoSuchTransaction, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
131 |
cnx.transaction_actions, self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
132 |
self.assertRaises(NoSuchTransaction, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
133 |
cnx.undo_transaction, self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
134 |
txs = cnx.undoable_transactions() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
135 |
self.assertEqual(len(txs), 0) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
136 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
137 |
def test_undoable_transactions(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
138 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
139 |
toto = self.toto(cnx) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
140 |
e = cnx.create_entity('EmailAddress', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
141 |
address=u'toto@logilab.org', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
142 |
reverse_use_email=toto) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
143 |
txuuid1 = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
144 |
toto.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
145 |
txuuid2 = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
146 |
undoable_transactions = cnx.undoable_transactions |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
147 |
txs = undoable_transactions(action='D') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
148 |
self.assertEqual(len(txs), 1, txs) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
149 |
self.assertEqual(txs[0].uuid, txuuid2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
150 |
txs = undoable_transactions(action='C') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
151 |
self.assertEqual(len(txs), 2, txs) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
152 |
self.assertEqual(txs[0].uuid, txuuid1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
153 |
self.assertEqual(txs[1].uuid, self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
154 |
txs = undoable_transactions(eid=toto.eid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
155 |
self.assertEqual(len(txs), 3) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
156 |
self.assertEqual(txs[0].uuid, txuuid2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
157 |
self.assertEqual(txs[1].uuid, txuuid1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
158 |
self.assertEqual(txs[2].uuid, self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
159 |
txs = undoable_transactions(etype='CWUser') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
160 |
self.assertEqual(len(txs), 2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
161 |
txs = undoable_transactions(etype='CWUser', action='C') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
162 |
self.assertEqual(len(txs), 1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
163 |
self.assertEqual(txs[0].uuid, self.txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
164 |
txs = undoable_transactions(etype='EmailAddress', action='D') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
165 |
self.assertEqual(len(txs), 0) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
166 |
txs = undoable_transactions(etype='EmailAddress', action='D', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
167 |
public=False) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
168 |
self.assertEqual(len(txs), 1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
169 |
self.assertEqual(txs[0].uuid, txuuid2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
170 |
txs = undoable_transactions(eid=toto.eid, action='R', public=False) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
171 |
self.assertEqual(len(txs), 1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
172 |
self.assertEqual(txs[0].uuid, txuuid2) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
173 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
174 |
def test_undo_deletion_base(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
175 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
176 |
toto = self.toto(cnx) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
177 |
e = cnx.create_entity('EmailAddress', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
178 |
address=u'toto@logilab.org', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
179 |
reverse_use_email=toto) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
180 |
# entity with inlined relation |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
181 |
p = cnx.create_entity('CWProperty', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
182 |
pkey=u'ui.default-text-format', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
183 |
value=u'text/rest', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
184 |
for_user=toto) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
185 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
186 |
txs = cnx.undoable_transactions() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
187 |
self.assertEqual(len(txs), 2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
188 |
toto.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
189 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
190 |
actions = cnx.transaction_info(txuuid).actions_list() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
191 |
self.assertEqual(len(actions), 1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
192 |
toto.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
193 |
e.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
194 |
self.assertUndoTransaction(cnx, txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
195 |
undotxuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
196 |
self.assertEqual(undotxuuid, None) # undo not undoable |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
197 |
self.assertTrue(cnx.execute('Any X WHERE X eid %(x)s', {'x': toto.eid})) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
198 |
self.assertTrue(cnx.execute('Any X WHERE X eid %(x)s', {'x': e.eid})) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
199 |
self.assertTrue(cnx.execute('Any X WHERE X has_text "toto@logilab"')) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
200 |
self.assertEqual(toto.cw_adapt_to('IWorkflowable').state, 'activated') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
201 |
self.assertEqual(toto.cw_adapt_to('IEmailable').get_email(), 'toto@logilab.org') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
202 |
self.assertEqual([(p.pkey, p.value) for p in toto.reverse_for_user], |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
203 |
[('ui.default-text-format', 'text/rest')]) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
204 |
self.assertEqual([g.name for g in toto.in_group], |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
205 |
['users']) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
206 |
self.assertEqual([et.name for et in toto.related('is', entities=True)], |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
207 |
['CWUser']) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
208 |
self.assertEqual([et.name for et in toto.is_instance_of], |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
209 |
['CWUser']) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
210 |
# undoing shouldn't be visble in undoable transaction, and the undone |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
211 |
# transaction should be removed |
10260
0e61be7bff10
[server/test] kill remaining 3.19 deprecation warnings in undo tests
Julien Cristau <julien.cristau@logilab.fr>
parents:
10210
diff
changeset
|
212 |
txs = cnx.undoable_transactions() |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
213 |
self.assertEqual(len(txs), 2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
214 |
self.assertRaises(NoSuchTransaction, |
10260
0e61be7bff10
[server/test] kill remaining 3.19 deprecation warnings in undo tests
Julien Cristau <julien.cristau@logilab.fr>
parents:
10210
diff
changeset
|
215 |
cnx.transaction_info, txuuid) |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
216 |
with self.admin_access.repo_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
217 |
with cnx.ensure_cnx_set: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
218 |
self.check_transaction_deleted(cnx, txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
219 |
# the final test: check we can login with the previously deleted user |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
220 |
with self.new_access('toto').client_cnx(): |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
221 |
pass |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
222 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
223 |
def test_undo_deletion_integrity_1(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
224 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
225 |
# 'Personne fiche Card with' '??' cardinality |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
226 |
c = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
227 |
p = cnx.create_entity('Personne', nom=u'louis', fiche=c) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
228 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
229 |
c.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
230 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
231 |
c2 = cnx.create_entity('Card', title=u'hip', content=u'hip') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
232 |
p.cw_set(fiche=c2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
233 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
234 |
self.assertUndoTransaction(cnx, txuuid, [ |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
235 |
"Can't restore object relation fiche to entity " |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
236 |
"%s which is already linked using this relation." % p.eid]) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
237 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
238 |
p.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
239 |
self.assertEqual(p.fiche[0].eid, c2.eid) |
10210
633d85ba9f72
[undo/test] check that the entity was restored even though the fiche relation wasn't
Julien Cristau <julien.cristau@logilab.fr>
parents:
10207
diff
changeset
|
240 |
# we restored the card |
633d85ba9f72
[undo/test] check that the entity was restored even though the fiche relation wasn't
Julien Cristau <julien.cristau@logilab.fr>
parents:
10207
diff
changeset
|
241 |
self.assertTrue(cnx.entity_from_eid(c.eid)) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
242 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
243 |
def test_undo_deletion_integrity_2(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
244 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
245 |
# test validation error raised if we can't restore a required relation |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
246 |
g = cnx.create_entity('CWGroup', name=u'staff') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
247 |
cnx.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.totoeid}) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
248 |
self.toto(cnx).cw_set(in_group=g) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
249 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
250 |
self.toto(cnx).cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
251 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
252 |
g.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
253 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
254 |
self.assertUndoTransaction(cnx, txuuid, [ |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
255 |
u"Can't restore relation in_group, object entity " |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
256 |
"%s doesn't exist anymore." % g.eid]) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
257 |
with self.assertRaises(ValidationError) as cm: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
258 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
259 |
cm.exception.translate(unicode) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
260 |
self.assertEqual(cm.exception.entity, self.totoeid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
261 |
self.assertEqual(cm.exception.errors, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
262 |
{'in_group-subject': u'at least one relation in_group is ' |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
263 |
'required on CWUser (%s)' % self.totoeid}) |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
264 |
|
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
265 |
def test_undo_creation_1(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
266 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
267 |
c = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
268 |
p = cnx.create_entity('Personne', nom=u'louis', fiche=c) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
269 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
270 |
self.assertUndoTransaction(cnx, txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
271 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
272 |
self.assertFalse(cnx.execute('Any X WHERE X eid %(x)s', {'x': c.eid})) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
273 |
self.assertFalse(cnx.execute('Any X WHERE X eid %(x)s', {'x': p.eid})) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
274 |
self.assertFalse(cnx.execute('Any X,Y WHERE X fiche Y')) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
275 |
with self.admin_access.repo_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
276 |
with cnx.ensure_cnx_set: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
277 |
for eid in (p.eid, c.eid): |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
278 |
self.assertFalse(cnx.system_sql( |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
279 |
'SELECT * FROM entities WHERE eid=%s' % eid).fetchall()) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
280 |
self.assertFalse(cnx.system_sql( |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
281 |
'SELECT 1 FROM owned_by_relation WHERE eid_from=%s' % eid).fetchall()) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
282 |
# added by sql in hooks (except when using dataimport) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
283 |
self.assertFalse(cnx.system_sql( |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
284 |
'SELECT 1 FROM is_relation WHERE eid_from=%s' % eid).fetchall()) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
285 |
self.assertFalse(cnx.system_sql( |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
286 |
'SELECT 1 FROM is_instance_of_relation WHERE eid_from=%s' % eid).fetchall()) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
287 |
self.check_transaction_deleted(cnx, txuuid) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
288 |
|
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
289 |
def test_undo_creation_integrity_1(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
290 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
291 |
tutu = self.create_user(cnx, 'tutu', commit=False) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
292 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
293 |
email = cnx.create_entity('EmailAddress', address=u'tutu@cubicweb.org') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
294 |
prop = cnx.create_entity('CWProperty', pkey=u'ui.default-text-format', |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
295 |
value=u'text/html') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
296 |
tutu.cw_set(use_email=email, reverse_for_user=prop) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
297 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
298 |
with self.assertRaises(ValidationError) as cm: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
299 |
cnx.undo_transaction(txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
300 |
self.assertEqual(cm.exception.entity, tutu.eid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
301 |
self.assertEqual(cm.exception.errors, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
302 |
{None: 'some later transaction(s) touch entity, undo them first'}) |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
303 |
|
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
304 |
def test_undo_creation_integrity_2(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
305 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
306 |
g = cnx.create_entity('CWGroup', name=u'staff') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
307 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
308 |
cnx.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.totoeid}) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
309 |
self.toto(cnx).cw_set(in_group=g) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
310 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
311 |
with self.assertRaises(ValidationError) as cm: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
312 |
cnx.undo_transaction(txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
313 |
self.assertEqual(cm.exception.entity, g.eid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
314 |
self.assertEqual(cm.exception.errors, |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
315 |
{None: 'some later transaction(s) touch entity, undo them first'}) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5762
diff
changeset
|
316 |
# self.assertEqual(errors, |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
317 |
# [u"Can't restore relation in_group, object entity " |
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
318 |
# "%s doesn't exist anymore." % g.eid]) |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
319 |
# with self.assertRaises(ValidationError) as cm: cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
320 |
# self.assertEqual(cm.exception.entity, self.totoeid) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
321 |
# self.assertEqual(cm.exception.errors, |
5076
b0e6134b4324
[undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4913
diff
changeset
|
322 |
# {'in_group-subject': u'at least one relation in_group is ' |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
323 |
# 'required on CWUser (%s)' % self.totoeid}) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
324 |
|
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff
changeset
|
325 |
# test implicit 'replacement' of an inlined relation |
5760
b6453e606d25
[test] miss main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
326 |
|
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
327 |
def test_undo_inline_rel_remove_ok(self): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
328 |
"""Undo remove relation Personne (?) fiche (?) Card |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
329 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
330 |
NB: processed by `_undo_r` as expected""" |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
331 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
332 |
c = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
333 |
p = cnx.create_entity('Personne', nom=u'louis', fiche=c) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
334 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
335 |
p.cw_set(fiche=None) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
336 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
337 |
self.assertUndoTransaction(cnx, txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
338 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
339 |
p.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
340 |
self.assertEqual(p.fiche[0].eid, c.eid) |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
341 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
342 |
def test_undo_inline_rel_remove_ko(self): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
343 |
"""Restore an inlined relation to a deleted entity, with an error. |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
344 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
345 |
NB: processed by `_undo_r` as expected""" |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
346 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
347 |
c = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
348 |
p = cnx.create_entity('Personne', nom=u'louis', fiche=c) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
349 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
350 |
p.cw_set(fiche=None) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
351 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
352 |
c.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
353 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
354 |
self.assertUndoTransaction(cnx, txuuid, [ |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
355 |
"Can't restore relation fiche, object entity %d doesn't exist anymore." % c.eid]) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
356 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
357 |
p.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
358 |
self.assertFalse(p.fiche) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
359 |
with self.admin_access.repo_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
360 |
with cnx.ensure_cnx_set: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
361 |
self.assertIsNone(cnx.system_sql( |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
362 |
'SELECT cw_fiche FROM cw_Personne WHERE cw_eid=%s' % p.eid).fetchall()[0][0]) |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
363 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
364 |
def test_undo_inline_rel_add_ok(self): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
365 |
"""Undo add relation Personne (?) fiche (?) Card |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
366 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
367 |
Caution processed by `_undo_u`, not `_undo_a` !""" |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
368 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
369 |
c = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
370 |
p = cnx.create_entity('Personne', nom=u'louis') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
371 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
372 |
p.cw_set(fiche=c) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
373 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
374 |
self.assertUndoTransaction(cnx, txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
375 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
376 |
p.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
377 |
self.assertFalse(p.fiche) |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
378 |
|
10207
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
379 |
def test_undo_inline_rel_delete_ko(self): |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
380 |
with self.admin_access.client_cnx() as cnx: |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
381 |
c = cnx.create_entity('Card', title=u'hop', content=u'hop') |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
382 |
txuuid = cnx.commit() |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
383 |
p = cnx.create_entity('Personne', nom=u'louis', fiche=c) |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
384 |
cnx.commit() |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
385 |
integrityerror = self.repo.sources_by_uri['system'].dbhelper.dbapi_module.IntegrityError |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
386 |
with self.assertRaises(integrityerror): |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
387 |
cnx.undo_transaction(txuuid) |
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
388 |
|
5ec5d17b5e5b
[undo/test] if we try to delete an entity referenced by an inline relation, we fail
Julien Cristau <julien.cristau@logilab.fr>
parents:
10000
diff
changeset
|
389 |
|
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
390 |
def test_undo_inline_rel_add_ko(self): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
391 |
"""Undo add relation Personne (?) fiche (?) Card |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
392 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
393 |
Caution processed by `_undo_u`, not `_undo_a` !""" |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
394 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
395 |
c = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
396 |
p = cnx.create_entity('Personne', nom=u'louis') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
397 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
398 |
p.cw_set(fiche=c) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
399 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
400 |
c.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
401 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
402 |
self.assertUndoTransaction(cnx, txuuid) |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
403 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
404 |
def test_undo_inline_rel_replace_ok(self): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
405 |
"""Undo changing relation Personne (?) fiche (?) Card |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
406 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
407 |
Caution processed by `_undo_u` """ |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
408 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
409 |
c1 = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
410 |
c2 = cnx.create_entity('Card', title=u'hip', content=u'hip') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
411 |
p = cnx.create_entity('Personne', nom=u'louis', fiche=c1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
412 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
413 |
p.cw_set(fiche=c2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
414 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
415 |
self.assertUndoTransaction(cnx, txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
416 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
417 |
p.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
418 |
self.assertEqual(p.fiche[0].eid, c1.eid) |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
419 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
420 |
def test_undo_inline_rel_replace_ko(self): |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
421 |
"""Undo changing relation Personne (?) fiche (?) Card, with an error |
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
422 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
423 |
Caution processed by `_undo_u` """ |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
424 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
425 |
c1 = cnx.create_entity('Card', title=u'hop', content=u'hop') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
426 |
c2 = cnx.create_entity('Card', title=u'hip', content=u'hip') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
427 |
p = cnx.create_entity('Personne', nom=u'louis', fiche=c1) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
428 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
429 |
p.cw_set(fiche=c2) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
430 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
431 |
c1.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
432 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
433 |
self.assertUndoTransaction(cnx, txuuid, [ |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
434 |
"can't restore entity %s of type Personne, target of fiche (eid %s)" |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
435 |
" does not exist any longer" % (p.eid, c1.eid)]) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
436 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
437 |
p.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
438 |
self.assertFalse(p.fiche) |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
439 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
440 |
def test_undo_attr_update_ok(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
441 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
442 |
p = cnx.create_entity('Personne', nom=u'toto') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
443 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
444 |
p.cw_set(nom=u'titi') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
445 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
446 |
self.assertUndoTransaction(cnx, txuuid) |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
447 |
p.cw_clear_all_caches() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
448 |
self.assertEqual(p.nom, u'toto') |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
449 |
|
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
450 |
def test_undo_attr_update_ko(self): |
9786
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
451 |
with self.admin_access.client_cnx() as cnx: |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
452 |
p = cnx.create_entity('Personne', nom=u'toto') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
453 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
454 |
p.cw_set(nom=u'titi') |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
455 |
txuuid = cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
456 |
p.cw_delete() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
457 |
cnx.commit() |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
458 |
self.assertUndoTransaction(cnx, txuuid, [ |
57dbd4450373
[tests/undo] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9020
diff
changeset
|
459 |
u"can't restore state of entity %s, it has been deleted inbetween" % p.eid]) |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
460 |
|
7530
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
461 |
|
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
462 |
class UndoExceptionInUnicode(CubicWebTC): |
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
463 |
|
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
464 |
# problem occurs in string manipulation for python < 2.6 |
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
465 |
def test___unicode__method(self): |
8265
9747ab9230ad
[repo, undo] Finish repository-side implementation of the undo feature (closes #893940)
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
7791
diff
changeset
|
466 |
u = _UndoException(u"voilĂ ") |
7530
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
467 |
self.assertIsInstance(unicode(u), unicode) |
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
468 |
|
15178bf89fb6
[server] fix unicode conversion capability in UndoException
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
7424
diff
changeset
|
469 |
|
5760
b6453e606d25
[test] miss main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
470 |
if __name__ == '__main__': |
b6453e606d25
[test] miss main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
471 |
from logilab.common.testlib import unittest_main |
b6453e606d25
[test] miss main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
472 |
unittest_main() |