author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 13 Aug 2009 10:58:29 +0200 | |
changeset 2809 | 04fa75d43af4 |
parent 2773 | b2530e3e0afb |
child 2968 | 0e3460341023 |
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 |
|
63 |
||
0 | 64 |
def test_in_state_notification(self): |
65 |
result = [] |
|
66 |
# test both email notification and transition_information |
|
67 |
# whatever if we can connect to the default stmp server, transaction |
|
68 |
# should not fail |
|
69 |
def in_state_changed(session, eidfrom, rtype, eidto): |
|
70 |
tr = previous_state(session, eidfrom) |
|
71 |
if tr is None: |
|
72 |
result.append(tr) |
|
73 |
return |
|
74 |
content = u'trÀnsition from %s to %s' % (tr.name, entity_name(session, eidto)) |
|
75 |
result.append(content) |
|
76 |
SendMailOp(session, msg=content, recipients=['test@logilab.fr']) |
|
77 |
self.hm.register_hook(in_state_changed, |
|
78 |
'before_add_relation', 'in_state') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
79 |
self.execute('INSERT CWUser X: X login "paf", X upassword "wouf", X in_state S, X in_group G WHERE S name "activated", G name "users"') |
0 | 80 |
self.assertEquals(result, [None]) |
81 |
searchedops = [op for op in self.session.pending_operations |
|
82 |
if isinstance(op, SendMailOp)] |
|
83 |
self.assertEquals(len(searchedops), 0, |
|
84 |
self.session.pending_operations) |
|
85 |
self.commit() |
|
86 |
self.execute('SET X in_state S WHERE X login "paf", S name "deactivated"') |
|
87 |
self.assertEquals(result, [None, u'trÀnsition from activated to deactivated']) |
|
88 |
# one to send the mail, one to close the smtp connection |
|
89 |
searchedops = [op for op in self.session.pending_operations |
|
90 |
if isinstance(op, SendMailOp)] |
|
91 |
self.assertEquals(len(searchedops), 1, |
|
92 |
self.session.pending_operations) |
|
93 |
self.commit() |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
94 |
self.assertEquals([], self.session.pending_operations) |
1787 | 95 |
|
0 | 96 |
if __name__ == '__main__': |
97 |
unittest_main() |