author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 05 Aug 2009 17:23:06 +0200 | |
changeset 2696 | b45d852990d5 |
parent 2650 | 18aec79ec3a3 |
child 2773 | b2530e3e0afb |
child 2920 | 64322aa83a1d |
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 |
|
12 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
13 |
||
14 |
from cubicweb.sobjects.notification import construct_message_id, parse_message_id |
|
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() |
|
74 |
u = self.create_user('toto', req=req) |
|
75 |
assert u.req |
|
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
|
76 |
assert u.rset |
0 | 77 |
self.execute('SET X in_state S WHERE X eid %s, S name "deactivated"' % u.eid) |
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
|
78 |
v = self.vreg['views'].select('notif_status_change', req, rset=u.rset, row=0) |
1723 | 79 |
content = v.render(row=0, comment='yeah', |
80 |
previous_state='activated', |
|
81 |
current_state='deactivated') |
|
0 | 82 |
# remove date |
83 |
self.assertEquals(content, |
|
84 |
''' |
|
85 |
admin changed status from <activated> to <deactivated> for entity |
|
86 |
'toto' |
|
87 |
||
88 |
yeah |
|
89 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
90 |
url: http://testing.fr/cubicweb/cwuser/toto |
0 | 91 |
''') |
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
92 |
self.assertEquals(v.subject(), 'status changed cwuser #%s (admin)' % u.eid) |
0 | 93 |
|
94 |
if __name__ == '__main__': |
|
95 |
unittest_main() |