author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 12:17:59 +0200 | |
changeset 3413 | 5cd27d2cc64f |
parent 2968 | server/test/unittest_hookhelper.py@0e3460341023 |
child 3414 | fe6c99b96701 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
2 |
"""unit/functional tests for cubicweb.server.hook |
1977
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 |
|
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
11 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
12 |
from cubicweb.devtools.testlib import CubicWebTC |
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
13 |
from cubicweb.server.hook import LateOperation, Operation, SingleLastOperation |
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
14 |
from cubicweb.hooks import integrity, syncschema |
0 | 15 |
|
16 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
17 |
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
|
18 |
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
|
19 |
try: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
20 |
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
|
21 |
finally: |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
22 |
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
|
23 |
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
|
24 |
|
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
25 |
class HookHelpersTC(CubicWebTC): |
1787 | 26 |
|
0 | 27 |
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
|
28 |
CubicWebTC.setUp(self) |
0 | 29 |
self.hm = self.repo.hm |
1787 | 30 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
31 |
@clean_session_ops |
0 | 32 |
def test_late_operation(self): |
33 |
session = self.session |
|
34 |
l1 = LateOperation(session) |
|
35 |
l2 = LateOperation(session) |
|
36 |
l3 = Operation(session) |
|
37 |
self.assertEquals(session.pending_operations, [l3, l1, l2]) |
|
1787 | 38 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
39 |
@clean_session_ops |
0 | 40 |
def test_single_last_operation(self): |
41 |
session = self.session |
|
42 |
l0 = SingleLastOperation(session) |
|
43 |
l1 = LateOperation(session) |
|
44 |
l2 = LateOperation(session) |
|
45 |
l3 = Operation(session) |
|
46 |
self.assertEquals(session.pending_operations, [l3, l1, l2, l0]) |
|
47 |
l4 = SingleLastOperation(session) |
|
48 |
self.assertEquals(session.pending_operations, [l3, l1, l2, l4]) |
|
1787 | 49 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
50 |
@clean_session_ops |
0 | 51 |
def test_global_operation_order(self): |
52 |
session = self.session |
|
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
53 |
op1 = integrity._DelayedDeleteOp(session) |
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
54 |
op2 = syncschema.MemSchemaRDefDel(session) |
0 | 55 |
# equivalent operation generated by op2 but replace it here by op3 so we |
56 |
# can check the result... |
|
3413
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
57 |
op3 = syncschema.MemSchemaNotifyChanges(session) |
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
58 |
op4 = integrity._DelayedDeleteOp(session) |
5cd27d2cc64f
update imports, rename test module
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
59 |
op5 = integrity._CheckORelationOp(session) |
0 | 60 |
self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3]) |
1787 | 61 |
|
0 | 62 |
if __name__ == '__main__': |
63 |
unittest_main() |