server/test/unittest_hookhelper.py
branchtls-sprint
changeset 1787 71c143c0ada3
parent 1398 5fe84a5f7035
child 1977 606923dff11b
equal deleted inserted replaced
1786:eccd1885d42e 1787:71c143c0ada3
     2 """unit/functional tests for cubicweb.server.hookhelper"""
     2 """unit/functional tests for cubicweb.server.hookhelper"""
     3 
     3 
     4 from logilab.common.testlib import unittest_main
     4 from logilab.common.testlib import unittest_main
     5 from cubicweb.devtools.apptest import RepositoryBasedTC
     5 from cubicweb.devtools.apptest import RepositoryBasedTC
     6 
     6 
     7 from cubicweb.server.pool import LateOperation
     7 from cubicweb.server.pool import LateOperation, Operation, SingleLastOperation
     8 from cubicweb.server.hookhelper import *
     8 from cubicweb.server.hookhelper import *
     9 
     9 
    10 
    10 
    11 class HookHelpersTC(RepositoryBasedTC):
    11 class HookHelpersTC(RepositoryBasedTC):
    12     
    12 
    13     def setUp(self):
    13     def setUp(self):
    14         RepositoryBasedTC.setUp(self)
    14         RepositoryBasedTC.setUp(self)
    15         self.hm = self.repo.hm
    15         self.hm = self.repo.hm
    16     
    16 
    17     def test_late_operation(self):
    17     def test_late_operation(self):
    18         session = self.session
    18         session = self.session
    19         l1 = LateOperation(session)
    19         l1 = LateOperation(session)
    20         l2 = LateOperation(session)
    20         l2 = LateOperation(session)
    21         l3 = Operation(session)
    21         l3 = Operation(session)
    22         self.assertEquals(session.pending_operations, [l3, l1, l2])
    22         self.assertEquals(session.pending_operations, [l3, l1, l2])
    23         
    23 
    24     def test_single_last_operation(self):
    24     def test_single_last_operation(self):
    25         session = self.session
    25         session = self.session
    26         l0 = SingleLastOperation(session)
    26         l0 = SingleLastOperation(session)
    27         l1 = LateOperation(session)
    27         l1 = LateOperation(session)
    28         l2 = LateOperation(session)
    28         l2 = LateOperation(session)
    29         l3 = Operation(session)
    29         l3 = Operation(session)
    30         self.assertEquals(session.pending_operations, [l3, l1, l2, l0])
    30         self.assertEquals(session.pending_operations, [l3, l1, l2, l0])
    31         l4 = SingleLastOperation(session)
    31         l4 = SingleLastOperation(session)
    32         self.assertEquals(session.pending_operations, [l3, l1, l2, l4])
    32         self.assertEquals(session.pending_operations, [l3, l1, l2, l4])
    33         
    33 
    34     def test_global_operation_order(self):
    34     def test_global_operation_order(self):
    35         from cubicweb.server import hooks, schemahooks
    35         from cubicweb.server import hooks, schemahooks
    36         session = self.session
    36         session = self.session
    37         op1 = hooks.DelayedDeleteOp(session)
    37         op1 = hooks.DelayedDeleteOp(session)
    38         op2 = schemahooks.DelErdefOp(session)
    38         op2 = schemahooks.DelErdefOp(session)
    40         # can check the result...
    40         # can check the result...
    41         op3 = schemahooks.UpdateSchemaOp(session)
    41         op3 = schemahooks.UpdateSchemaOp(session)
    42         op4 = hooks.DelayedDeleteOp(session)
    42         op4 = hooks.DelayedDeleteOp(session)
    43         op5 = hooks.CheckORelationOp(session)
    43         op5 = hooks.CheckORelationOp(session)
    44         self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3])
    44         self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3])
    45                           
    45 
    46        
    46 
    47     def test_in_state_notification(self):
    47     def test_in_state_notification(self):
    48         result = []
    48         result = []
    49         # test both email notification and transition_information
    49         # test both email notification and transition_information
    50         # whatever if we can connect to the default stmp server, transaction
    50         # whatever if we can connect to the default stmp server, transaction
    51         # should not fail
    51         # should not fail
    76         self.commit()
    76         self.commit()
    77         searchedops = [op for op in self.session.pending_operations
    77         searchedops = [op for op in self.session.pending_operations
    78                        if isinstance(op, SendMailOp)]
    78                        if isinstance(op, SendMailOp)]
    79         self.assertEquals(len(searchedops), 0,
    79         self.assertEquals(len(searchedops), 0,
    80                           self.session.pending_operations)
    80                           self.session.pending_operations)
    81         
    81 
    82 if __name__ == '__main__':
    82 if __name__ == '__main__':
    83     unittest_main()
    83     unittest_main()