author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 24 Jul 2009 15:20:14 +0200 | |
changeset 2487 | c4c13cf8cd7b |
parent 2455 | 5346d9f3d5ec |
child 2637 | 07103211e511 |
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 |
|
11 |
from cubicweb.devtools.apptest import RepositoryBasedTC |
|
12 |
||
1787 | 13 |
from cubicweb.server.pool import LateOperation, Operation, SingleLastOperation |
0 | 14 |
from cubicweb.server.hookhelper import * |
15 |
||
16 |
||
17 |
class HookHelpersTC(RepositoryBasedTC): |
|
1787 | 18 |
|
0 | 19 |
def setUp(self): |
20 |
RepositoryBasedTC.setUp(self) |
|
21 |
self.hm = self.repo.hm |
|
1787 | 22 |
|
0 | 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]) |
|
1787 | 29 |
|
0 | 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]) |
|
1787 | 39 |
|
0 | 40 |
def test_global_operation_order(self): |
41 |
from cubicweb.server import hooks, schemahooks |
|
42 |
session = self.session |
|
43 |
op1 = hooks.DelayedDeleteOp(session) |
|
2455
5346d9f3d5ec
[tests] fixes (including two operations renaming)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
44 |
op2 = schemahooks.DeleteRelationDefOp(session) |
0 | 45 |
# equivalent operation generated by op2 but replace it here by op3 so we |
46 |
# can check the result... |
|
47 |
op3 = schemahooks.UpdateSchemaOp(session) |
|
48 |
op4 = hooks.DelayedDeleteOp(session) |
|
49 |
op5 = hooks.CheckORelationOp(session) |
|
50 |
self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3]) |
|
1787 | 51 |
|
52 |
||
0 | 53 |
def test_in_state_notification(self): |
54 |
result = [] |
|
55 |
# test both email notification and transition_information |
|
56 |
# whatever if we can connect to the default stmp server, transaction |
|
57 |
# should not fail |
|
58 |
def in_state_changed(session, eidfrom, rtype, eidto): |
|
59 |
tr = previous_state(session, eidfrom) |
|
60 |
if tr is None: |
|
61 |
result.append(tr) |
|
62 |
return |
|
63 |
content = u'trÀnsition from %s to %s' % (tr.name, entity_name(session, eidto)) |
|
64 |
result.append(content) |
|
65 |
SendMailOp(session, msg=content, recipients=['test@logilab.fr']) |
|
66 |
self.hm.register_hook(in_state_changed, |
|
67 |
'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
|
68 |
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 | 69 |
self.assertEquals(result, [None]) |
70 |
searchedops = [op for op in self.session.pending_operations |
|
71 |
if isinstance(op, SendMailOp)] |
|
72 |
self.assertEquals(len(searchedops), 0, |
|
73 |
self.session.pending_operations) |
|
74 |
self.commit() |
|
75 |
self.execute('SET X in_state S WHERE X login "paf", S name "deactivated"') |
|
76 |
self.assertEquals(result, [None, u'trÀnsition from activated to deactivated']) |
|
77 |
# one to send the mail, one to close the smtp connection |
|
78 |
searchedops = [op for op in self.session.pending_operations |
|
79 |
if isinstance(op, SendMailOp)] |
|
80 |
self.assertEquals(len(searchedops), 1, |
|
81 |
self.session.pending_operations) |
|
82 |
self.commit() |
|
83 |
searchedops = [op for op in self.session.pending_operations |
|
84 |
if isinstance(op, SendMailOp)] |
|
85 |
self.assertEquals(len(searchedops), 0, |
|
86 |
self.session.pending_operations) |
|
1787 | 87 |
|
0 | 88 |
if __name__ == '__main__': |
89 |
unittest_main() |