author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 26 Sep 2011 19:09:12 +0200 | |
branch | stable |
changeset 7867 | 0abed94a9859 |
parent 7244 | a918f76441ce |
child 7791 | 31bb51ea5485 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
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 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
20 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1902
diff
changeset
|
21 |
""" |
0 | 22 |
from socket import gethostname |
23 |
||
24 |
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
|
25 |
from cubicweb.devtools.testlib import CubicWebTC, MAILBOX |
0 | 26 |
|
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3428
diff
changeset
|
27 |
from cubicweb.mail import construct_message_id, parse_message_id |
0 | 28 |
|
29 |
class MessageIdTC(TestCase): |
|
30 |
def test_base(self): |
|
31 |
msgid1 = construct_message_id('testapp', 21) |
|
32 |
msgid2 = construct_message_id('testapp', 21) |
|
33 |
self.failIfEqual(msgid1, msgid2) |
|
34 |
self.failIf('&' in msgid1) |
|
35 |
self.failIf('=' in msgid1) |
|
36 |
self.failIf('/' in msgid1) |
|
37 |
self.failIf('+' in msgid1) |
|
38 |
values = parse_message_id(msgid1, 'testapp') |
|
39 |
self.failUnless(values) |
|
40 |
# parse_message_id should work with or without surrounding <> |
|
41 |
self.failUnlessEqual(values, parse_message_id(msgid1[1:-1], 'testapp')) |
|
42 |
self.failUnlessEqual(values['eid'], '21') |
|
43 |
self.failUnless('timestamp' in values) |
|
44 |
self.failUnlessEqual(parse_message_id(msgid1[1:-1], 'anotherapp'), None) |
|
1723 | 45 |
|
0 | 46 |
def test_notimestamp(self): |
47 |
msgid1 = construct_message_id('testapp', 21, False) |
|
48 |
msgid2 = construct_message_id('testapp', 21, False) |
|
49 |
values = parse_message_id(msgid1, 'testapp') |
|
50 |
self.failUnlessEqual(values, {'eid': '21'}) |
|
51 |
||
52 |
def test_parse_message_doesnt_raise(self): |
|
53 |
self.failUnlessEqual(parse_message_id('oijioj@bla.bla', 'tesapp'), None) |
|
54 |
self.failUnlessEqual(parse_message_id('oijioj@bla', 'tesapp'), None) |
|
55 |
self.failUnlessEqual(parse_message_id('oijioj', 'tesapp'), None) |
|
56 |
||
57 |
||
58 |
def test_nonregr_empty_message_id(self): |
|
59 |
for eid in (1, 12, 123, 1234): |
|
60 |
msgid1 = construct_message_id('testapp', eid, 12) |
|
6415 | 61 |
self.assertNotEqual(msgid1, '<@testapp.%s>' % gethostname()) |
1723 | 62 |
|
0 | 63 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
64 |
class RecipientsFinderTC(CubicWebTC): |
0 | 65 |
def test(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
66 |
urset = self.execute('CWUser X WHERE X login "admin"') |
0 | 67 |
self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X ' |
68 |
'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
|
69 |
self.execute('INSERT CWProperty X: X pkey "ui.language", X value "fr", X for_user U ' |
0 | 70 |
'WHERE U eid %(x)s', {'x': urset[0][0]}) |
71 |
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
|
72 |
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
|
73 |
self.request(), rset=urset) |
0 | 74 |
self.set_option('default-recipients-mode', 'none') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
75 |
self.assertEqual(finder.recipients(), []) |
0 | 76 |
self.set_option('default-recipients-mode', 'users') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
77 |
self.assertEqual(finder.recipients(), [(u'admin@logilab.fr', 'fr')]) |
0 | 78 |
self.set_option('default-recipients-mode', 'default-dest-addrs') |
79 |
self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
80 |
self.assertEqual(finder.recipients(), [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')]) |
1723 | 81 |
|
0 | 82 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
83 |
class StatusChangeViewsTC(CubicWebTC): |
1723 | 84 |
|
0 | 85 |
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
|
86 |
req = self.request() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6415
diff
changeset
|
87 |
u = self.create_user(req, 'toto') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
88 |
u.cw_adapt_to('IWorkflowable').fire_transition('deactivate', comment=u'yeah') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
89 |
self.failIf(MAILBOX) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
90 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
91 |
self.assertEqual(len(MAILBOX), 1) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
92 |
email = MAILBOX[0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
93 |
self.assertEqual(email.content, |
0 | 94 |
''' |
95 |
admin changed status from <activated> to <deactivated> for entity |
|
96 |
'toto' |
|
97 |
||
98 |
yeah |
|
99 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
100 |
url: http://testing.fr/cubicweb/cwuser/toto |
0 | 101 |
''') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
102 |
self.assertEqual(email.subject, 'status changed cwuser #%s (admin)' % u.eid) |
0 | 103 |
|
104 |
if __name__ == '__main__': |
|
105 |
unittest_main() |