author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 20 Aug 2009 17:44:27 +0200 | |
branch | 3.5 |
changeset 2920 | 64322aa83a1d |
parent 2650 | 18aec79ec3a3 |
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 |
from socket import gethostname |
10 |
||
11 |
from logilab.common.testlib import unittest_main, TestCase |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
12 |
from cubicweb.devtools.apptest import EnvBasedTC, MAILBOX |
0 | 13 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
14 |
from cubicweb.common.mail import construct_message_id, parse_message_id |
0 | 15 |
|
16 |
class MessageIdTC(TestCase): |
|
17 |
def test_base(self): |
|
18 |
msgid1 = construct_message_id('testapp', 21) |
|
19 |
msgid2 = construct_message_id('testapp', 21) |
|
20 |
self.failIfEqual(msgid1, msgid2) |
|
21 |
self.failIf('&' in msgid1) |
|
22 |
self.failIf('=' in msgid1) |
|
23 |
self.failIf('/' in msgid1) |
|
24 |
self.failIf('+' in msgid1) |
|
25 |
values = parse_message_id(msgid1, 'testapp') |
|
26 |
self.failUnless(values) |
|
27 |
# parse_message_id should work with or without surrounding <> |
|
28 |
self.failUnlessEqual(values, parse_message_id(msgid1[1:-1], 'testapp')) |
|
29 |
self.failUnlessEqual(values['eid'], '21') |
|
30 |
self.failUnless('timestamp' in values) |
|
31 |
self.failUnlessEqual(parse_message_id(msgid1[1:-1], 'anotherapp'), None) |
|
1723 | 32 |
|
0 | 33 |
def test_notimestamp(self): |
34 |
msgid1 = construct_message_id('testapp', 21, False) |
|
35 |
msgid2 = construct_message_id('testapp', 21, False) |
|
36 |
values = parse_message_id(msgid1, 'testapp') |
|
37 |
self.failUnlessEqual(values, {'eid': '21'}) |
|
38 |
||
39 |
def test_parse_message_doesnt_raise(self): |
|
40 |
self.failUnlessEqual(parse_message_id('oijioj@bla.bla', 'tesapp'), None) |
|
41 |
self.failUnlessEqual(parse_message_id('oijioj@bla', 'tesapp'), None) |
|
42 |
self.failUnlessEqual(parse_message_id('oijioj', 'tesapp'), None) |
|
43 |
||
44 |
||
45 |
def test_nonregr_empty_message_id(self): |
|
46 |
for eid in (1, 12, 123, 1234): |
|
47 |
msgid1 = construct_message_id('testapp', eid, 12) |
|
48 |
self.assertNotEquals(msgid1, '<@testapp.%s>' % gethostname()) |
|
1723 | 49 |
|
0 | 50 |
|
51 |
class RecipientsFinderTC(EnvBasedTC): |
|
52 |
def test(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
53 |
urset = self.execute('CWUser X WHERE X login "admin"') |
0 | 54 |
self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X ' |
55 |
'WHERE U eid %(x)s', {'x': urset[0][0]}) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
56 |
self.execute('INSERT CWProperty X: X pkey "ui.language", X value "fr", X for_user U ' |
0 | 57 |
'WHERE U eid %(x)s', {'x': urset[0][0]}) |
58 |
self.commit() # commit so that admin get its properties updated |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
59 |
finder = self.vreg['components'].select('recipients_finder', |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
60 |
self.request(), rset=urset) |
0 | 61 |
self.set_option('default-recipients-mode', 'none') |
62 |
self.assertEquals(finder.recipients(), []) |
|
63 |
self.set_option('default-recipients-mode', 'users') |
|
64 |
self.assertEquals(finder.recipients(), [(u'admin@logilab.fr', 'fr')]) |
|
65 |
self.set_option('default-recipients-mode', 'default-dest-addrs') |
|
66 |
self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr') |
|
67 |
self.assertEquals(finder.recipients(), [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')]) |
|
1723 | 68 |
|
0 | 69 |
|
70 |
class StatusChangeViewsTC(EnvBasedTC): |
|
1723 | 71 |
|
0 | 72 |
def test_status_change_view(self): |
73 |
req = self.session() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
74 |
u = self.create_user('toto', req=req)#, commit=False) XXX in cw 3.6, and remove set_pool |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
75 |
req.set_pool() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
76 |
u.fire_transition('deactivate', comment=u'yeah') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
77 |
self.failIf(MAILBOX) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
78 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
79 |
self.assertEquals(len(MAILBOX), 1) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
80 |
email = MAILBOX[0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
81 |
self.assertEquals(email.content, |
0 | 82 |
''' |
83 |
admin changed status from <activated> to <deactivated> for entity |
|
84 |
'toto' |
|
85 |
||
86 |
yeah |
|
87 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
88 |
url: http://testing.fr/cubicweb/cwuser/toto |
0 | 89 |
''') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
90 |
self.assertEquals(email.subject, 'status changed cwuser #%s (admin)' % u.eid) |
0 | 91 |
|
92 |
if __name__ == '__main__': |
|
93 |
unittest_main() |