author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 21 Aug 2009 16:26:20 +0200 | |
changeset 2968 | 0e3460341023 |
parent 2773 | b2530e3e0afb |
parent 2920 | 64322aa83a1d |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
2 |
"""unit/functional tests for cubicweb.server.hookhelper |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
3 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
4 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
8 |
""" |
0 | 9 |
|
10 |
from logilab.common.testlib import unittest_main |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
11 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 12 |
|
1787 | 13 |
from cubicweb.server.pool import LateOperation, Operation, SingleLastOperation |
0 | 14 |
from cubicweb.server.hookhelper import * |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
15 |
from cubicweb.server import hooks, schemahooks |
0 | 16 |
|
17 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
18 |
def clean_session_ops(func): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
19 |
def wrapper(self, *args, **kwargs): |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
20 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
21 |
return func(self, *args, **kwargs) |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
22 |
finally: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
23 |
self.session.pending_operations[:] = [] |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
24 |
return wrapper |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
25 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
26 |
class HookHelpersTC(CubicWebTC): |
1787 | 27 |
|
0 | 28 |
def setUp(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
29 |
CubicWebTC.setUp(self) |
0 | 30 |
self.hm = self.repo.hm |
1787 | 31 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
32 |
@clean_session_ops |
0 | 33 |
def test_late_operation(self): |
34 |
session = self.session |
|
35 |
l1 = LateOperation(session) |
|
36 |
l2 = LateOperation(session) |
|
37 |
l3 = Operation(session) |
|
38 |
self.assertEquals(session.pending_operations, [l3, l1, l2]) |
|
1787 | 39 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
40 |
@clean_session_ops |
0 | 41 |
def test_single_last_operation(self): |
42 |
session = self.session |
|
43 |
l0 = SingleLastOperation(session) |
|
44 |
l1 = LateOperation(session) |
|
45 |
l2 = LateOperation(session) |
|
46 |
l3 = Operation(session) |
|
47 |
self.assertEquals(session.pending_operations, [l3, l1, l2, l0]) |
|
48 |
l4 = SingleLastOperation(session) |
|
49 |
self.assertEquals(session.pending_operations, [l3, l1, l2, l4]) |
|
1787 | 50 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
51 |
@clean_session_ops |
0 | 52 |
def test_global_operation_order(self): |
53 |
session = self.session |
|
54 |
op1 = hooks.DelayedDeleteOp(session) |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2455
diff
changeset
|
55 |
op2 = schemahooks.MemSchemaRDefDel(session) |
0 | 56 |
# equivalent operation generated by op2 but replace it here by op3 so we |
57 |
# can check the result... |
|
2637
07103211e511
R [test] update and fix deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2455
diff
changeset
|
58 |
op3 = schemahooks.MemSchemaNotifyChanges(session) |
0 | 59 |
op4 = hooks.DelayedDeleteOp(session) |
60 |
op5 = hooks.CheckORelationOp(session) |
|
61 |
self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3]) |
|
1787 | 62 |
|
0 | 63 |
if __name__ == '__main__': |
64 |
unittest_main() |