server/test/unittest_undo.py
changeset 5557 1a534c596bff
parent 5556 9ab2b4c74baf
child 5762 730d458ec1bf
equal deleted inserted replaced
5556:9ab2b4c74baf 5557:1a534c596bff
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """
       
    19 
       
    20 """
       
    21 from __future__ import with_statement
    18 from __future__ import with_statement
    22 
    19 
    23 from cubicweb import ValidationError
    20 from cubicweb import ValidationError
    24 from cubicweb.devtools.testlib import CubicWebTC
    21 from cubicweb.devtools.testlib import CubicWebTC
    25 from cubicweb.transaction import *
    22 from cubicweb.transaction import *
   102         toto = self.toto
    99         toto = self.toto
   103         e = self.session.create_entity('EmailAddress',
   100         e = self.session.create_entity('EmailAddress',
   104                                        address=u'toto@logilab.org',
   101                                        address=u'toto@logilab.org',
   105                                        reverse_use_email=toto)
   102                                        reverse_use_email=toto)
   106         txuuid1 = self.commit()
   103         txuuid1 = self.commit()
   107         toto.delete()
   104         toto.cw_delete()
   108         txuuid2 = self.commit()
   105         txuuid2 = self.commit()
   109         undoable_transactions = self.cnx.undoable_transactions
   106         undoable_transactions = self.cnx.undoable_transactions
   110         txs = undoable_transactions(action='D')
   107         txs = undoable_transactions(action='D')
   111         self.assertEquals(len(txs), 1, txs)
   108         self.assertEquals(len(txs), 1, txs)
   112         self.assertEquals(txs[0].uuid, txuuid2)
   109         self.assertEquals(txs[0].uuid, txuuid2)
   145                                        value=u'text/rest',
   142                                        value=u'text/rest',
   146                                        for_user=toto)
   143                                        for_user=toto)
   147         self.commit()
   144         self.commit()
   148         txs = self.cnx.undoable_transactions()
   145         txs = self.cnx.undoable_transactions()
   149         self.assertEquals(len(txs), 2)
   146         self.assertEquals(len(txs), 2)
   150         toto.delete()
   147         toto.cw_delete()
   151         txuuid = self.commit()
   148         txuuid = self.commit()
   152         actions = self.cnx.transaction_info(txuuid).actions_list()
   149         actions = self.cnx.transaction_info(txuuid).actions_list()
   153         self.assertEquals(len(actions), 1)
   150         self.assertEquals(len(actions), 1)
   154         toto.clear_all_caches()
   151         toto.clear_all_caches()
   155         e.clear_all_caches()
   152         e.clear_all_caches()
   184         session = self.session
   181         session = self.session
   185         # 'Personne fiche Card with' '??' cardinality
   182         # 'Personne fiche Card with' '??' cardinality
   186         c = session.create_entity('Card', title=u'hop', content=u'hop')
   183         c = session.create_entity('Card', title=u'hop', content=u'hop')
   187         p = session.create_entity('Personne', nom=u'louis', fiche=c)
   184         p = session.create_entity('Personne', nom=u'louis', fiche=c)
   188         self.commit()
   185         self.commit()
   189         c.delete()
   186         c.cw_delete()
   190         txuuid = self.commit()
   187         txuuid = self.commit()
   191         c2 = session.create_entity('Card', title=u'hip', content=u'hip')
   188         c2 = session.create_entity('Card', title=u'hip', content=u'hip')
   192         p.set_relations(fiche=c2)
   189         p.set_relations(fiche=c2)
   193         self.commit()
   190         self.commit()
   194         errors = self.cnx.undo_transaction(txuuid)
   191         errors = self.cnx.undo_transaction(txuuid)
   205         session = self.session
   202         session = self.session
   206         g = session.create_entity('CWGroup', name=u'staff')
   203         g = session.create_entity('CWGroup', name=u'staff')
   207         session.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.toto.eid})
   204         session.execute('DELETE U in_group G WHERE U eid %(x)s', {'x': self.toto.eid})
   208         self.toto.set_relations(in_group=g)
   205         self.toto.set_relations(in_group=g)
   209         self.commit()
   206         self.commit()
   210         self.toto.delete()
   207         self.toto.cw_delete()
   211         txuuid = self.commit()
   208         txuuid = self.commit()
   212         g.delete()
   209         g.cw_delete()
   213         self.commit()
   210         self.commit()
   214         errors = self.cnx.undo_transaction(txuuid)
   211         errors = self.cnx.undo_transaction(txuuid)
   215         self.assertEquals(errors,
   212         self.assertEquals(errors,
   216                           [u"Can't restore relation in_group, object entity "
   213                           [u"Can't restore relation in_group, object entity "
   217                           "%s doesn't exist anymore." % g.eid])
   214                           "%s doesn't exist anymore." % g.eid])