author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 17 Dec 2015 15:17:45 +0100 | |
changeset 11029 | c9d12d1d3081 |
parent 11011 | 94bbf6d7eaf8 |
child 11083 | 4b18b1027d02 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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:
4252
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 |
|
0 | 20 |
from socket import gethostname |
21 |
||
22 |
from logilab.common.testlib import unittest_main, TestCase |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
23 |
from cubicweb.devtools.testlib import CubicWebTC, MAILBOX |
0 | 24 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3428
diff
changeset
|
25 |
from cubicweb.mail import construct_message_id, parse_message_id |
0 | 26 |
|
27 |
class MessageIdTC(TestCase): |
|
28 |
def test_base(self): |
|
29 |
msgid1 = construct_message_id('testapp', 21) |
|
30 |
msgid2 = construct_message_id('testapp', 21) |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
31 |
self.assertNotEqual(msgid1, msgid2) |
9675
8aabfefc8a81
[test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9674
diff
changeset
|
32 |
self.assertNotIn('&', msgid1) |
8aabfefc8a81
[test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9674
diff
changeset
|
33 |
self.assertNotIn('=', msgid1) |
8aabfefc8a81
[test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9674
diff
changeset
|
34 |
self.assertNotIn('/', msgid1) |
8aabfefc8a81
[test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9674
diff
changeset
|
35 |
self.assertNotIn('+', msgid1) |
0 | 36 |
values = parse_message_id(msgid1, 'testapp') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
37 |
self.assertTrue(values) |
0 | 38 |
# parse_message_id should work with or without surrounding <> |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
39 |
self.assertEqual(values, parse_message_id(msgid1[1:-1], 'testapp')) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
40 |
self.assertEqual(values['eid'], '21') |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
8955
diff
changeset
|
41 |
self.assertIn('timestamp', values) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
42 |
self.assertEqual(parse_message_id(msgid1[1:-1], 'anotherapp'), None) |
1723 | 43 |
|
0 | 44 |
def test_notimestamp(self): |
45 |
msgid1 = construct_message_id('testapp', 21, False) |
|
46 |
msgid2 = construct_message_id('testapp', 21, False) |
|
47 |
values = parse_message_id(msgid1, 'testapp') |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
48 |
self.assertEqual(values, {'eid': '21'}) |
0 | 49 |
|
50 |
def test_parse_message_doesnt_raise(self): |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
51 |
self.assertEqual(parse_message_id('oijioj@bla.bla', 'tesapp'), None) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
52 |
self.assertEqual(parse_message_id('oijioj@bla', 'tesapp'), None) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
53 |
self.assertEqual(parse_message_id('oijioj', 'tesapp'), None) |
0 | 54 |
|
55 |
||
56 |
def test_nonregr_empty_message_id(self): |
|
57 |
for eid in (1, 12, 123, 1234): |
|
58 |
msgid1 = construct_message_id('testapp', eid, 12) |
|
6415 | 59 |
self.assertNotEqual(msgid1, '<@testapp.%s>' % gethostname()) |
1723 | 60 |
|
8955
8ef2d90512b5
[test/notification] merge related test classe
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8931
diff
changeset
|
61 |
class NotificationTC(CubicWebTC): |
0 | 62 |
|
8955
8ef2d90512b5
[test/notification] merge related test classe
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8931
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
'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
|
68 |
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
|
69 |
'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
|
70 |
req.cnx.commit() # commit so that admin get its properties updated |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
self.set_option('default-recipients-mode', 'users') |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
76 |
self.assertEqual(finder.recipients(), [(u'admin@logilab.fr', 'fr')]) |
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
77 |
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
|
78 |
self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr') |
11011
94bbf6d7eaf8
[test/py3k] fix test_recipients_finder
Julien Cristau <julien.cristau@logilab.fr>
parents:
9745
diff
changeset
|
79 |
self.assertEqual(list(finder.recipients()), [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')]) |
1723 | 80 |
|
0 | 81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
''' |
0 | 92 |
admin changed status from <activated> to <deactivated> for entity |
93 |
'toto' |
|
94 |
||
95 |
yeah |
|
96 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
97 |
url: http://testing.fr/cubicweb/cwuser/toto |
0 | 98 |
''') |
9745
c013d5d76f66
[test] update sobjects/test/unittest_notification to cw 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9675
diff
changeset
|
99 |
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
|
100 |
'status changed CWUser #%s (admin)' % u.eid) |
0 | 101 |
|
102 |
if __name__ == '__main__': |
|
103 |
unittest_main() |