1 # -*- coding: utf-8 -*- |
|
2 """unit/functional tests for cubicweb.server.hookhelper |
|
3 |
|
4 :organization: Logilab |
|
5 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
|
6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
|
8 """ |
|
9 |
|
10 from logilab.common.testlib import unittest_main |
|
11 from cubicweb.devtools.apptest import RepositoryBasedTC |
|
12 |
|
13 from cubicweb.server.pool import LateOperation, Operation, SingleLastOperation |
|
14 from cubicweb.server.hookhelper import * |
|
15 |
|
16 |
|
17 class HookHelpersTC(RepositoryBasedTC): |
|
18 |
|
19 def setUp(self): |
|
20 RepositoryBasedTC.setUp(self) |
|
21 self.hm = self.repo.hm |
|
22 |
|
23 def test_late_operation(self): |
|
24 session = self.session |
|
25 l1 = LateOperation(session) |
|
26 l2 = LateOperation(session) |
|
27 l3 = Operation(session) |
|
28 self.assertEquals(session.pending_operations, [l3, l1, l2]) |
|
29 |
|
30 def test_single_last_operation(self): |
|
31 session = self.session |
|
32 l0 = SingleLastOperation(session) |
|
33 l1 = LateOperation(session) |
|
34 l2 = LateOperation(session) |
|
35 l3 = Operation(session) |
|
36 self.assertEquals(session.pending_operations, [l3, l1, l2, l0]) |
|
37 l4 = SingleLastOperation(session) |
|
38 self.assertEquals(session.pending_operations, [l3, l1, l2, l4]) |
|
39 |
|
40 def test_global_operation_order(self): |
|
41 from cubicweb.server import hooks, schemahooks |
|
42 session = self.session |
|
43 op1 = hooks.DelayedDeleteOp(session) |
|
44 op2 = schemahooks.MemSchemaRDefDel(session) |
|
45 # equivalent operation generated by op2 but replace it here by op3 so we |
|
46 # can check the result... |
|
47 op3 = schemahooks.MemSchemaNotifyChanges(session) |
|
48 op4 = hooks.DelayedDeleteOp(session) |
|
49 op5 = hooks.CheckORelationOp(session) |
|
50 self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3]) |
|
51 |
|
52 if __name__ == '__main__': |
|
53 unittest_main() |
|