author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 08 Apr 2010 17:50:37 +0200 | |
branch | stable |
changeset 5189 | 84d4587a92bc |
parent 4252 | 6c4f109c2b03 |
child 5421 | 8167de96c523 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2920
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
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 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
12 |
from cubicweb.devtools.testlib import CubicWebTC, MAILBOX |
0 | 13 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3428
diff
changeset
|
14 |
from cubicweb.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 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
51 |
class RecipientsFinderTC(CubicWebTC): |
0 | 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 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
70 |
class StatusChangeViewsTC(CubicWebTC): |
1723 | 71 |
|
0 | 72 |
def test_status_change_view(self): |
3428
d689ee586295
[tests] fix status change notification test: initial user state is set on commit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2968
diff
changeset
|
73 |
req = self.request() |
d689ee586295
[tests] fix status change notification test: initial user state is set on commit
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2968
diff
changeset
|
74 |
u = self.create_user('toto', req=req) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
75 |
u.fire_transition('deactivate', comment=u'yeah') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
76 |
self.failIf(MAILBOX) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
77 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
78 |
self.assertEquals(len(MAILBOX), 1) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
79 |
email = MAILBOX[0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
80 |
self.assertEquals(email.content, |
0 | 81 |
''' |
82 |
admin changed status from <activated> to <deactivated> for entity |
|
83 |
'toto' |
|
84 |
||
85 |
yeah |
|
86 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
87 |
url: http://testing.fr/cubicweb/cwuser/toto |
0 | 88 |
''') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
89 |
self.assertEquals(email.subject, 'status changed cwuser #%s (admin)' % u.eid) |
0 | 90 |
|
91 |
if __name__ == '__main__': |
|
92 |
unittest_main() |