server/test/unittest_undo.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 31 Mar 2010 12:32:39 +0200
branchstable
changeset 5104 7aab5286f037
parent 5076 b0e6134b4324
child 5174 78438ad513ca
child 5421 8167de96c523
permissions -rw-r--r--
[test] that doesn't smell good but fix the test...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     1
"""
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     2
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     4
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     6
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     7
"""
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     8
from __future__ import with_statement
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
     9
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    10
from cubicweb import ValidationError
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    11
from cubicweb.devtools.testlib import CubicWebTC
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    12
from cubicweb.transaction import *
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    13
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    14
class UndoableTransactionTC(CubicWebTC):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    15
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    16
    def setup_database(self):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    17
        self.session.undo_actions = set('CUDAR')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    18
        self.toto = self.create_user('toto', password='toto', groups=('users',),
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    19
                                     commit=False)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    20
        self.txuuid = self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    21
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    22
    def tearDown(self):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    23
        self.restore_connection()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    24
        self.session.undo_support = set()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    25
        super(UndoableTransactionTC, self).tearDown()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    26
5076
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    27
    def check_transaction_deleted(self, txuuid):
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    28
        # also check transaction actions have been properly deleted
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    29
        cu = self.session.system_sql(
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    30
            "SELECT * from tx_entity_actions WHERE tx_uuid='%s'" % txuuid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    31
        self.failIf(cu.fetchall())
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    32
        cu = self.session.system_sql(
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    33
            "SELECT * from tx_relation_actions WHERE tx_uuid='%s'" % txuuid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    34
        self.failIf(cu.fetchall())
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
    35
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    36
    def test_undo_api(self):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    37
        self.failUnless(self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    38
        # test transaction api
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    39
        self.assertRaises(NoSuchTransaction,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    40
                          self.cnx.transaction_info, 'hop')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    41
        self.assertRaises(NoSuchTransaction,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    42
                          self.cnx.transaction_actions, 'hop')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    43
        self.assertRaises(NoSuchTransaction,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    44
                          self.cnx.undo_transaction, 'hop')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    45
        txinfo = self.cnx.transaction_info(self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    46
        self.failUnless(txinfo.datetime)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    47
        self.assertEquals(txinfo.user_eid, self.session.user.eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    48
        self.assertEquals(txinfo.user().login, 'admin')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    49
        actions = txinfo.actions_list()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    50
        self.assertEquals(len(actions), 2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    51
        actions = txinfo.actions_list(public=False)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    52
        self.assertEquals(len(actions), 6)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    53
        a1 = actions[0]
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    54
        self.assertEquals(a1.action, 'C')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    55
        self.assertEquals(a1.eid, self.toto.eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    56
        self.assertEquals(a1.etype,'CWUser')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    57
        self.assertEquals(a1.changes, None)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    58
        self.assertEquals(a1.public, True)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    59
        self.assertEquals(a1.order, 1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    60
        a4 = actions[3]
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    61
        self.assertEquals(a4.action, 'A')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    62
        self.assertEquals(a4.rtype, 'in_group')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    63
        self.assertEquals(a4.eid_from, self.toto.eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    64
        self.assertEquals(a4.eid_to, self.toto.in_group[0].eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    65
        self.assertEquals(a4.order, 4)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    66
        for i, rtype in ((1, 'owned_by'), (2, 'owned_by'),
5104
7aab5286f037 [test] that doesn't smell good but fix the test...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5076
diff changeset
    67
                         (4, 'in_state'), (5, 'created_by')):
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    68
            a = actions[i]
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    69
            self.assertEquals(a.action, 'A')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    70
            self.assertEquals(a.eid_from, self.toto.eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    71
            self.assertEquals(a.rtype, rtype)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    72
            self.assertEquals(a.order, i+1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    73
        # test undoable_transactions
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    74
        txs = self.cnx.undoable_transactions()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    75
        self.assertEquals(len(txs), 1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    76
        self.assertEquals(txs[0].uuid, self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    77
        # test transaction_info / undoable_transactions security
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    78
        cnx = self.login('anon')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    79
        self.assertRaises(NoSuchTransaction,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    80
                          cnx.transaction_info, self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    81
        self.assertRaises(NoSuchTransaction,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    82
                          cnx.transaction_actions, self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    83
        self.assertRaises(NoSuchTransaction,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    84
                          cnx.undo_transaction, self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    85
        txs = cnx.undoable_transactions()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    86
        self.assertEquals(len(txs), 0)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    87
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    88
    def test_undoable_transactions(self):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    89
        toto = self.toto
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    90
        e = self.session.create_entity('EmailAddress',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    91
                                       address=u'toto@logilab.org',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    92
                                       reverse_use_email=toto)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    93
        txuuid1 = self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    94
        toto.delete()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    95
        txuuid2 = self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    96
        undoable_transactions = self.cnx.undoable_transactions
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    97
        txs = undoable_transactions(action='D')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    98
        self.assertEquals(len(txs), 1, txs)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
    99
        self.assertEquals(txs[0].uuid, txuuid2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   100
        txs = undoable_transactions(action='C')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   101
        self.assertEquals(len(txs), 2, txs)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   102
        self.assertEquals(txs[0].uuid, txuuid1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   103
        self.assertEquals(txs[1].uuid, self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   104
        txs = undoable_transactions(eid=toto.eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   105
        self.assertEquals(len(txs), 3)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   106
        self.assertEquals(txs[0].uuid, txuuid2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   107
        self.assertEquals(txs[1].uuid, txuuid1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   108
        self.assertEquals(txs[2].uuid, self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   109
        txs = undoable_transactions(etype='CWUser')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   110
        self.assertEquals(len(txs), 2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   111
        txs = undoable_transactions(etype='CWUser', action='C')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   112
        self.assertEquals(len(txs), 1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   113
        self.assertEquals(txs[0].uuid, self.txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   114
        txs = undoable_transactions(etype='EmailAddress', action='D')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   115
        self.assertEquals(len(txs), 0)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   116
        txs = undoable_transactions(etype='EmailAddress', action='D',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   117
                                    public=False)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   118
        self.assertEquals(len(txs), 1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   119
        self.assertEquals(txs[0].uuid, txuuid2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   120
        txs = undoable_transactions(eid=toto.eid, action='R', public=False)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   121
        self.assertEquals(len(txs), 1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   122
        self.assertEquals(txs[0].uuid, txuuid2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   123
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   124
    def test_undo_deletion_base(self):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   125
        toto = self.toto
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   126
        e = self.session.create_entity('EmailAddress',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   127
                                       address=u'toto@logilab.org',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   128
                                       reverse_use_email=toto)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   129
        # entity with inlined relation
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   130
        p = self.session.create_entity('CWProperty',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   131
                                       pkey=u'ui.default-text-format',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   132
                                       value=u'text/rest',
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   133
                                       for_user=toto)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   134
        self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   135
        txs = self.cnx.undoable_transactions()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   136
        self.assertEquals(len(txs), 2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   137
        toto.delete()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   138
        txuuid = self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   139
        actions = self.cnx.transaction_info(txuuid).actions_list()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   140
        self.assertEquals(len(actions), 1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   141
        toto.clear_all_caches()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   142
        e.clear_all_caches()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   143
        errors = self.cnx.undo_transaction(txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   144
        undotxuuid = self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   145
        self.assertEquals(undotxuuid, None) # undo not undoable
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   146
        self.assertEquals(errors, [])
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   147
        self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': toto.eid}, 'x'))
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   148
        self.failUnless(self.execute('Any X WHERE X eid %(x)s', {'x': e.eid}, 'x'))
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   149
        self.failUnless(self.execute('Any X WHERE X has_text "toto@logilab"'))
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   150
        self.assertEquals(toto.state, 'activated')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   151
        self.assertEquals(toto.get_email(), 'toto@logilab.org')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   152
        self.assertEquals([(p.pkey, p.value) for p in toto.reverse_for_user],
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   153
                          [('ui.default-text-format', 'text/rest')])
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   154
        self.assertEquals([g.name for g in toto.in_group],
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   155
                          ['users'])
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   156
        self.assertEquals([et.name for et in toto.related('is', entities=True)],
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   157
                          ['CWUser'])
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   158
        self.assertEquals([et.name for et in toto.is_instance_of],
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   159
                          ['CWUser'])
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   160
        # undoing shouldn't be visble in undoable transaction, and the undoed
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   161
        # transaction should be removed
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   162
        txs = self.cnx.undoable_transactions()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   163
        self.assertEquals(len(txs), 2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   164
        self.assertRaises(NoSuchTransaction,
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   165
                          self.cnx.transaction_info, txuuid)
5076
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   166
        self.check_transaction_deleted(txuuid)
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   167
        # the final test: check we can login with the previously deleted user
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   168
        self.login('toto')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   169
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   170
    def test_undo_deletion_integrity_1(self):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   171
        session = self.session
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   172
        # 'Personne fiche Card with' '??' cardinality
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   173
        c = session.create_entity('Card', title=u'hop', content=u'hop')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   174
        p = session.create_entity('Personne', nom=u'louis', fiche=c)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   175
        self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   176
        c.delete()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   177
        txuuid = self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   178
        c2 = session.create_entity('Card', title=u'hip', content=u'hip')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   179
        p.set_relations(fiche=c2)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   180
        self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   181
        errors = self.cnx.undo_transaction(txuuid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   182
        self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   183
        p.clear_all_caches()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   184
        self.assertEquals(p.fiche[0].eid, c2.eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   185
        self.assertEquals(len(errors), 1)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   186
        self.assertEquals(errors[0],
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   187
                          "Can't restore object relation fiche to entity "
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   188
                          "%s which is already linked using this relation." % p.eid)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   189
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   190
    def test_undo_deletion_integrity_2(self):
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   191
        # test validation error raised if we can't restore a required relation
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   192
        session = self.session
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   193
        g = session.create_entity('CWGroup', name=u'staff')
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   194
        session.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.toto.eid})
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   195
        self.toto.set_relations(in_group=g)
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   196
        self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   197
        self.toto.delete()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   198
        txuuid = self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   199
        g.delete()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   200
        self.commit()
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   201
        errors = self.cnx.undo_transaction(txuuid)
5076
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   202
        self.assertEquals(errors,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   203
                          [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
   204
                          "%s doesn't exist anymore." % g.eid])
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   205
        ex = self.assertRaises(ValidationError, self.commit)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   206
        self.assertEquals(ex.entity, self.toto.eid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   207
        self.assertEquals(ex.errors,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   208
                          {'in_group-subject': u'at least one relation in_group is '
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   209
                           'required on CWUser (%s)' % self.toto.eid})
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   210
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   211
    def test_undo_creation_1(self):
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   212
        session = self.session
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   213
        c = session.create_entity('Card', title=u'hop', content=u'hop')
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   214
        p = session.create_entity('Personne', nom=u'louis', fiche=c)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   215
        txuuid = self.commit()
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   216
        errors = self.cnx.undo_transaction(txuuid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   217
        self.commit()
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   218
        self.failIf(errors)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   219
        self.failIf(self.execute('Any X WHERE X eid %(x)s', {'x': c.eid}, 'x'))
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   220
        self.failIf(self.execute('Any X WHERE X eid %(x)s', {'x': p.eid}, 'x'))
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   221
        self.failIf(self.execute('Any X,Y WHERE X fiche Y'))
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   222
        self.session.set_pool()
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   223
        for eid in (p.eid, c.eid):
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   224
            self.failIf(session.system_sql(
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   225
                'SELECT * FROM entities WHERE eid=%s' % eid).fetchall())
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   226
            self.failIf(session.system_sql(
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   227
                'SELECT 1 FROM owned_by_relation WHERE eid_from=%s' % eid).fetchall())
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   228
            # added by sql in hooks (except when using dataimport)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   229
            self.failIf(session.system_sql(
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   230
                'SELECT 1 FROM is_relation WHERE eid_from=%s' % eid).fetchall())
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   231
            self.failIf(session.system_sql(
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   232
                'SELECT 1 FROM is_instance_of_relation WHERE eid_from=%s' % eid).fetchall())
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   233
        self.check_transaction_deleted(txuuid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   234
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   235
5076
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   236
    def test_undo_creation_integrity_1(self):
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   237
        session = self.session
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   238
        tutu = self.create_user('tutu', commit=False)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   239
        txuuid = self.commit()
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   240
        email = self.request().create_entity('EmailAddress', address=u'tutu@cubicweb.org')
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   241
        prop = self.request().create_entity('CWProperty', pkey=u'ui.default-text-format',
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   242
                                            value=u'text/html')
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   243
        tutu.set_relations(use_email=email, reverse_for_user=prop)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   244
        self.commit()
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   245
        ex = self.assertRaises(ValidationError,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   246
                               self.cnx.undo_transaction, txuuid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   247
        self.assertEquals(ex.entity, tutu.eid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   248
        self.assertEquals(ex.errors,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   249
                          {None: 'some later transaction(s) touch entity, undo them first'})
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   250
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   251
    def test_undo_creation_integrity_2(self):
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   252
        session = self.session
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   253
        g = session.create_entity('CWGroup', name=u'staff')
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   254
        txuuid = self.commit()
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   255
        session.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.toto.eid})
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   256
        self.toto.set_relations(in_group=g)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   257
        self.commit()
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   258
        ex = self.assertRaises(ValidationError,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   259
                               self.cnx.undo_transaction, txuuid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   260
        self.assertEquals(ex.entity, g.eid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   261
        self.assertEquals(ex.errors,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   262
                          {None: 'some later transaction(s) touch entity, undo them first'})
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   263
        # self.assertEquals(errors,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   264
        #                   [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
   265
        #                   "%s doesn't exist anymore." % g.eid])
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   266
        # ex = self.assertRaises(ValidationError, self.commit)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   267
        # self.assertEquals(ex.entity, self.toto.eid)
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   268
        # self.assertEquals(ex.errors,
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   269
        #                   {'in_group-subject': u'at least one relation in_group is '
b0e6134b4324 [undo] basic support for undoing of entity creation / relation addition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4913
diff changeset
   270
        #                    'required on CWUser (%s)' % self.toto.eid})
4913
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   271
083b4d454192 server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
diff changeset
   272
    # test implicit 'replacement' of an inlined relation