author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 30 Nov 2010 15:05:07 +0100 | |
changeset 6712 | 3e6cd6048be8 |
parent 6340 | 470d8e828fda |
child 8731 | 93c0c31875ac |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
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
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
19 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
20 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
21 |
""" |
0 | 22 |
import re |
23 |
||
24 |
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
|
25 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 26 |
|
27 |
from cubicweb.sobjects.supervising import SendMailOp, SupervisionMailOp |
|
28 |
||
29 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
30 |
class SupervisingTC(CubicWebTC): |
0 | 31 |
|
32 |
def setup_database(self): |
|
4049
5838a4b0766d
3.5 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
33 |
req = self.request() |
5838a4b0766d
3.5 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
34 |
req.create_entity('Card', title=u"une news !", content=u"cubicweb c'est beau") |
5838a4b0766d
3.5 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
35 |
req.create_entity('Card', title=u"une autre news !", content=u"cubicweb c'est beau") |
5838a4b0766d
3.5 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
36 |
req.create_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
5838a4b0766d
3.5 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
37 |
req.create_entity('Comment', content=u"Yo !") |
0 | 38 |
self.execute('SET C comments B WHERE B title "une autre news !", C content "Yo !"') |
39 |
self.vreg.config.global_set_option('supervising-addrs', 'test@logilab.fr') |
|
40 |
||
1723 | 41 |
|
0 | 42 |
def test_supervision(self): |
43 |
# do some modification |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
44 |
user = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
45 |
'WHERE G name "users"').get_entity(0, 0) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
46 |
self.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': user.eid}) |
0 | 47 |
self.execute('DELETE Card B WHERE B title "une news !"') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
48 |
self.execute('SET X bookmarked_by U WHERE X is Bookmark, U eid %(x)s', {'x': user.eid}) |
0 | 49 |
self.execute('SET X content "duh?" WHERE X is Comment') |
50 |
self.execute('DELETE X comments Y WHERE Y is Card, Y title "une autre news !"') |
|
51 |
# check only one supervision email operation |
|
4842 | 52 |
session = self.session |
0 | 53 |
sentops = [op for op in session.pending_operations |
54 |
if isinstance(op, SupervisionMailOp)] |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
55 |
self.assertEqual(len(sentops), 1) |
0 | 56 |
# check view content |
57 |
op = sentops[0] |
|
58 |
view = sentops[0]._get_view() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
59 |
self.assertEqual(view.recipients(), ['test@logilab.fr']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
60 |
self.assertEqual(view.subject(), '[data supervision] changes summary') |
2102
268659907769
finish to update transaction data api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
61 |
data = view.render(changes=session.transaction_data.get('pendingchanges')).strip() |
0 | 62 |
data = re.sub('#\d+', '#EID', data) |
63 |
data = re.sub('/\d+', '/EID', data) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
64 |
self.assertMultiLineEqual('''user admin has made the following change(s): |
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 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
|
67 |
http://testing.fr/cubicweb/cwuser/toto |
0 | 68 |
|
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
69 |
* added relation in_group from cwuser #EID to cwgroup #EID |
0 | 70 |
|
71 |
* deleted card #EID (une news !) |
|
72 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
73 |
* added relation bookmarked_by from bookmark #EID to cwuser #EID |
0 | 74 |
|
75 |
* updated comment #EID (#EID) |
|
76 |
http://testing.fr/cubicweb/comment/EID |
|
77 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
78 |
* deleted relation comments from comment #EID to card #EID''', |
0 | 79 |
data) |
80 |
# check prepared email |
|
81 |
op._prepare_email() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
82 |
self.assertEqual(len(op.to_send), 1) |
0 | 83 |
self.assert_(op.to_send[0][0]) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
84 |
self.assertEqual(op.to_send[0][1], ['test@logilab.fr']) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
85 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
86 |
# some other changes ####### |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
87 |
user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
88 |
sentops = [op for op in session.pending_operations |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
89 |
if isinstance(op, SupervisionMailOp)] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
90 |
self.assertEqual(len(sentops), 1) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
91 |
# check view content |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
92 |
op = sentops[0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
93 |
view = sentops[0]._get_view() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
94 |
data = view.render(changes=session.transaction_data.get('pendingchanges')).strip() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
95 |
data = re.sub('#\d+', '#EID', data) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
96 |
data = re.sub('/\d+', '/EID', data) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
97 |
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
|
98 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
99 |
* changed state of cwuser #EID (toto) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
100 |
from state activated to state deactivated |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
101 |
http://testing.fr/cubicweb/cwuser/toto''', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
102 |
data) |
0 | 103 |
|
104 |
def test_nonregr1(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
105 |
session = self.session |
0 | 106 |
# do some unlogged modification |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4842
diff
changeset
|
107 |
self.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': session.user.eid}) |
0 | 108 |
self.commit() # no crash |
109 |
||
1723 | 110 |
|
0 | 111 |
if __name__ == '__main__': |
112 |
unittest_main() |