author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 21 Jul 2009 23:09:27 +0200 | |
branch | stable |
changeset 2413 | b1bea4cab594 |
parent 1977 | 606923dff11b |
child 2058 | 7ef12c03447c |
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 |
|
59 |
finder = self.vreg.select_component('recipients_finder', self.request(), urset) |
|
60 |
self.set_option('default-recipients-mode', 'none') |
|
61 |
self.assertEquals(finder.recipients(), []) |
|
62 |
self.set_option('default-recipients-mode', 'users') |
|
63 |
self.assertEquals(finder.recipients(), [(u'admin@logilab.fr', 'fr')]) |
|
64 |
self.set_option('default-recipients-mode', 'default-dest-addrs') |
|
65 |
self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr') |
|
66 |
self.assertEquals(finder.recipients(), [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')]) |
|
1723 | 67 |
|
0 | 68 |
|
69 |
class StatusChangeViewsTC(EnvBasedTC): |
|
1723 | 70 |
|
0 | 71 |
def test_status_change_view(self): |
72 |
req = self.session() |
|
73 |
u = self.create_user('toto', req=req) |
|
74 |
assert u.req |
|
75 |
self.execute('SET X in_state S WHERE X eid %s, S name "deactivated"' % u.eid) |
|
76 |
v = self.vreg.select_view('notif_status_change', req, u.rset, row=0) |
|
1723 | 77 |
content = v.render(row=0, comment='yeah', |
78 |
previous_state='activated', |
|
79 |
current_state='deactivated') |
|
0 | 80 |
# remove date |
81 |
self.assertEquals(content, |
|
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 |
''') |
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 |
self.assertEquals(v.subject(), 'status changed cwuser #%s (admin)' % u.eid) |
0 | 91 |
|
92 |
if __name__ == '__main__': |
|
93 |
unittest_main() |