author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 14 Oct 2009 16:30:46 +0200 | |
branch | stable |
changeset 3670 | b7ec030a5e10 |
parent 2922 | 996103009bc5 |
child 2968 | 0e3460341023 |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
2 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
3 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
4 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
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:
1902
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:
1902
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:
1902
diff
changeset
|
8 |
""" |
0 | 9 |
import re |
10 |
||
11 |
from logilab.common.testlib import unittest_main |
|
12 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
13 |
||
14 |
from cubicweb.sobjects.supervising import SendMailOp, SupervisionMailOp |
|
15 |
||
16 |
||
17 |
class SupervisingTC(EnvBasedTC): |
|
18 |
||
19 |
def setup_database(self): |
|
20 |
self.add_entity('Card', title=u"une news !", content=u"cubicweb c'est beau") |
|
21 |
self.add_entity('Card', title=u"une autre news !", content=u"cubicweb c'est beau") |
|
22 |
self.add_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
|
23 |
self.add_entity('Comment', content=u"Yo !") |
|
24 |
self.execute('SET C comments B WHERE B title "une autre news !", C content "Yo !"') |
|
25 |
self.vreg.config.global_set_option('supervising-addrs', 'test@logilab.fr') |
|
26 |
||
1723 | 27 |
|
0 | 28 |
def test_supervision(self): |
29 |
session = self.session() |
|
30 |
# do some modification |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
31 |
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
|
32 |
'WHERE G name "users"').get_entity(0, 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
33 |
self.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': user.eid}, 'x') |
0 | 34 |
self.execute('DELETE Card B WHERE B title "une news !"') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
35 |
self.execute('SET X bookmarked_by U WHERE X is Bookmark, U eid %(x)s', {'x': user.eid}, 'x') |
0 | 36 |
self.execute('SET X content "duh?" WHERE X is Comment') |
37 |
self.execute('DELETE X comments Y WHERE Y is Card, Y title "une autre news !"') |
|
38 |
# check only one supervision email operation |
|
39 |
sentops = [op for op in session.pending_operations |
|
40 |
if isinstance(op, SupervisionMailOp)] |
|
41 |
self.assertEquals(len(sentops), 1) |
|
42 |
# check view content |
|
43 |
op = sentops[0] |
|
44 |
view = sentops[0]._get_view() |
|
45 |
self.assertEquals(view.recipients(), ['test@logilab.fr']) |
|
46 |
self.assertEquals(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
|
47 |
data = view.render(changes=session.transaction_data.get('pendingchanges')).strip() |
0 | 48 |
data = re.sub('#\d+', '#EID', data) |
49 |
data = re.sub('/\d+', '/EID', data) |
|
50 |
self.assertTextEquals('''user admin has made the following change(s): |
|
51 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
52 |
* 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
|
53 |
http://testing.fr/cubicweb/cwuser/toto |
0 | 54 |
|
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
55 |
* added relation in_group from cwuser #EID to cwgroup #EID |
0 | 56 |
|
57 |
* deleted card #EID (une news !) |
|
58 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
59 |
* added relation bookmarked_by from bookmark #EID to cwuser #EID |
0 | 60 |
|
61 |
* updated comment #EID (#EID) |
|
62 |
http://testing.fr/cubicweb/comment/EID |
|
63 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
64 |
* deleted relation comments from comment #EID to card #EID''', |
0 | 65 |
data) |
66 |
# check prepared email |
|
67 |
op._prepare_email() |
|
1723 | 68 |
self.assertEquals(len(op.to_send), 1) |
0 | 69 |
self.assert_(op.to_send[0][0]) |
1723 | 70 |
self.assertEquals(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
|
71 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
72 |
# some other changes ####### |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
73 |
user.fire_transition('deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
74 |
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
|
75 |
if isinstance(op, SupervisionMailOp)] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
76 |
self.assertEquals(len(sentops), 1) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
77 |
# check view content |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
78 |
op = sentops[0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
79 |
view = sentops[0]._get_view() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
80 |
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
|
81 |
data = re.sub('#\d+', '#EID', data) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
82 |
data = re.sub('/\d+', '/EID', data) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
83 |
self.assertTextEquals('''user admin has made the following change(s): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
84 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
85 |
* changed state of cwuser #EID (toto) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
86 |
from state activated to state deactivated |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
87 |
http://testing.fr/cubicweb/cwuser/toto''', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2102
diff
changeset
|
88 |
data) |
0 | 89 |
|
90 |
def test_nonregr1(self): |
|
91 |
session = self.session() |
|
92 |
# do some unlogged modification |
|
93 |
self.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': session.user.eid}, 'x') |
|
94 |
self.commit() # no crash |
|
95 |
||
1723 | 96 |
|
0 | 97 |
if __name__ == '__main__': |
98 |
unittest_main() |