author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 11 Jun 2014 14:47:50 +0200 | |
changeset 10361 | 46d72f33c428 |
parent 9744 | 4693bf7ffb68 |
child 10600 | 180aa08cad48 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
9548
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8731
diff
changeset
|
2 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
import re |
20 |
||
21 |
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:
2102
diff
changeset
|
22 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 23 |
|
24 |
from cubicweb.sobjects.supervising import SendMailOp, SupervisionMailOp |
|
25 |
||
26 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
27 |
class SupervisingTC(CubicWebTC): |
0 | 28 |
|
29 |
def setup_database(self): |
|
9743
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
30 |
with self.admin_access.client_cnx() as cnx: |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
31 |
cnx.create_entity('Card', title=u"une news !", content=u"cubicweb c'est beau") |
9744
4693bf7ffb68
[test] simplify setup of sobjects/test/unittest_supervising.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9743
diff
changeset
|
32 |
card = cnx.create_entity('Card', title=u"une autre news !", content=u"cubicweb c'est beau") |
9743
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
33 |
cnx.create_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
9744
4693bf7ffb68
[test] simplify setup of sobjects/test/unittest_supervising.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9743
diff
changeset
|
34 |
cnx.create_entity('Comment', content=u"Yo !", comments=card) |
9743
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
35 |
cnx.commit() |
0 | 36 |
self.vreg.config.global_set_option('supervising-addrs', 'test@logilab.fr') |
37 |
||
1723 | 38 |
|
0 | 39 |
def test_supervision(self): |
40 |
# do some modification |
|
9743
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
41 |
with self.admin_access.repo_cnx() as cnx: |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
42 |
user = cnx.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G ' |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
43 |
'WHERE G name "users"').get_entity(0, 0) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
44 |
cnx.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': user.eid}) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
45 |
cnx.execute('DELETE Card B WHERE B title "une news !"') |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
46 |
cnx.execute('SET X bookmarked_by U WHERE X is Bookmark, U eid %(x)s', {'x': user.eid}) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
47 |
cnx.execute('SET X content "duh?" WHERE X is Comment') |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
48 |
cnx.execute('DELETE Comment C WHERE C comments Y, Y is Card, Y title "une autre news !"') |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
49 |
# check only one supervision email operation |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
50 |
sentops = [op for op in cnx.pending_operations |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
51 |
if isinstance(op, SupervisionMailOp)] |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
52 |
self.assertEqual(len(sentops), 1) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
53 |
# check view content |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
54 |
op = sentops[0] |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
55 |
view = sentops[0]._get_view() |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
56 |
self.assertEqual(view.recipients(), ['test@logilab.fr']) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
57 |
self.assertEqual(view.subject(), '[data supervision] changes summary') |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
58 |
data = view.render(changes=cnx.transaction_data.get('pendingchanges')).strip() |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
59 |
data = re.sub('#\d+', '#EID', data) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
60 |
data = re.sub('/\d+', '/EID', data) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
61 |
self.assertMultiLineEqual('''user admin has made the following change(s): |
0 | 62 |
|
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
63 |
* added cwuser #EID (toto) |
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
64 |
http://testing.fr/cubicweb/cwuser/toto |
0 | 65 |
|
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
66 |
* added relation in_group from cwuser #EID to cwgroup #EID |
0 | 67 |
|
68 |
* deleted card #EID (une news !) |
|
69 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
70 |
* added relation bookmarked_by from bookmark #EID to cwuser #EID |
0 | 71 |
|
8731
93c0c31875ac
[test/sobject] fix test regression
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
72 |
* updated comment #EID (duh?) |
0 | 73 |
http://testing.fr/cubicweb/comment/EID |
74 |
||
9548
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8731
diff
changeset
|
75 |
* deleted comment #EID (duh?)''', |
0 | 76 |
data) |
9743
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
77 |
# check prepared email |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
78 |
op._prepare_email() |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
79 |
self.assertEqual(len(op.to_send), 1) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
80 |
self.assert_(op.to_send[0][0]) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
81 |
self.assertEqual(op.to_send[0][1], ['test@logilab.fr']) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
82 |
cnx.commit() |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
83 |
# some other changes ####### |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
84 |
user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
85 |
sentops = [op for op in cnx.pending_operations |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
86 |
if isinstance(op, SupervisionMailOp)] |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
87 |
self.assertEqual(len(sentops), 1) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
88 |
# check view content |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
89 |
op = sentops[0] |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
90 |
view = sentops[0]._get_view() |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
91 |
data = view.render(changes=cnx.transaction_data.get('pendingchanges')).strip() |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
92 |
data = re.sub('#\d+', '#EID', data) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
93 |
data = re.sub('/\d+', '/EID', data) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
94 |
self.assertMultiLineEqual('''user admin has made the following change(s): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
95 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
96 |
* changed state of cwuser #EID (toto) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
97 |
from state activated to state deactivated |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
98 |
http://testing.fr/cubicweb/cwuser/toto''', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
99 |
data) |
0 | 100 |
|
101 |
def test_nonregr1(self): |
|
9743
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
102 |
with self.admin_access.repo_cnx() as cnx: |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
103 |
# do some unlogged modification |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
104 |
cnx.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': cnx.user.eid}) |
2bd234de9ff3
[test] update sobjects/test/unittest_supervising to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9548
diff
changeset
|
105 |
cnx.commit() # no crash |
0 | 106 |
|
1723 | 107 |
|
0 | 108 |
if __name__ == '__main__': |
109 |
unittest_main() |