author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Fri, 21 Oct 2016 18:10:15 +0200 | |
changeset 11735 | 7a170207acbf |
parent 11143 | ebb6809659a4 |
permissions | -rw-r--r-- |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
1 |
# 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:
4252
diff
changeset
|
2 |
# 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:
4252
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
4 |
# 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:
4252
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
6 |
# 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:
4252
diff
changeset
|
7 |
# 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:
4252
diff
changeset
|
8 |
# 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:
4252
diff
changeset
|
9 |
# 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:
4252
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# 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:
4252
diff
changeset
|
12 |
# 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:
4252
diff
changeset
|
13 |
# 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:
4252
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# 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:
4252
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
11083
4b18b1027d02
[test] Gather tests about mail module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11011
diff
changeset
|
18 |
"""Tests for notification sobjects""" |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
19 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
20 |
from cubicweb.devtools.testlib import CubicWebTC, MAILBOX |
0 | 21 |
|
1723 | 22 |
|
8955
8ef2d90512b5
[test/notification] merge related test classe
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8931
diff
changeset
|
23 |
class NotificationTC(CubicWebTC): |
0 | 24 |
|
8955
8ef2d90512b5
[test/notification] merge related test classe
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8931
diff
changeset
|
25 |
def test_recipients_finder(self): |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
26 |
with self.admin_access.web_request() as req: |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
27 |
urset = req.execute('CWUser X WHERE X login "admin"') |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
28 |
req.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X ' |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
29 |
'WHERE U eid %(x)s', {'x': urset[0][0]}) |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
30 |
req.execute('INSERT CWProperty X: X pkey "ui.language", X value "fr", X for_user U ' |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
31 |
'WHERE U eid %(x)s', {'x': urset[0][0]}) |
11083
4b18b1027d02
[test] Gather tests about mail module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11011
diff
changeset
|
32 |
req.cnx.commit() # commit so that admin get its properties updated |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
33 |
finder = self.vreg['components'].select('recipients_finder', |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
34 |
req, rset=urset) |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
35 |
self.set_option('default-recipients-mode', 'none') |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
36 |
self.assertEqual(finder.recipients(), []) |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
37 |
self.set_option('default-recipients-mode', 'users') |
11143
ebb6809659a4
[notification] avoid using InternalManager when we've got a CWUser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11129
diff
changeset
|
38 |
self.assertEqual(finder.recipients(), [req.user]) |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
39 |
self.set_option('default-recipients-mode', 'default-dest-addrs') |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
40 |
self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr') |
11083
4b18b1027d02
[test] Gather tests about mail module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11011
diff
changeset
|
41 |
self.assertEqual(list(finder.recipients()), |
4b18b1027d02
[test] Gather tests about mail module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11011
diff
changeset
|
42 |
[('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')]) |
1723 | 43 |
|
0 | 44 |
def test_status_change_view(self): |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
45 |
with self.admin_access.web_request() as req: |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
46 |
u = self.create_user(req, 'toto') |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
47 |
iwfable = u.cw_adapt_to('IWorkflowable') |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
48 |
iwfable.fire_transition('deactivate', comment=u'yeah') |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
49 |
self.assertFalse(MAILBOX) |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
50 |
req.cnx.commit() |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
51 |
self.assertEqual(len(MAILBOX), 1) |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
52 |
email = MAILBOX[0] |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
53 |
self.assertEqual(email.content, |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
54 |
''' |
0 | 55 |
admin changed status from <activated> to <deactivated> for entity |
56 |
'toto' |
|
57 |
||
58 |
yeah |
|
59 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
60 |
url: http://testing.fr/cubicweb/cwuser/toto |
0 | 61 |
''') |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
62 |
self.assertEqual(email.subject, |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
63 |
'status changed CWUser #%s (admin)' % u.eid) |
0 | 64 |
|
11083
4b18b1027d02
[test] Gather tests about mail module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11011
diff
changeset
|
65 |
|
0 | 66 |
if __name__ == '__main__': |
11083
4b18b1027d02
[test] Gather tests about mail module
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11011
diff
changeset
|
67 |
from logilab.common.testlib import unittest_main |
0 | 68 |
unittest_main() |