author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Wed, 27 May 2009 12:46:31 +0200 | |
branch | stable |
changeset 1958 | a9594cfd7c6d |
parent 1902 | d38a46498eb9 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: iso-8859-1 -*- |
2 |
from socket import gethostname |
|
3 |
||
4 |
from logilab.common.testlib import unittest_main, TestCase |
|
5 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
6 |
||
7 |
from cubicweb.sobjects.notification import construct_message_id, parse_message_id |
|
8 |
||
9 |
class MessageIdTC(TestCase): |
|
10 |
def test_base(self): |
|
11 |
msgid1 = construct_message_id('testapp', 21) |
|
12 |
msgid2 = construct_message_id('testapp', 21) |
|
13 |
self.failIfEqual(msgid1, msgid2) |
|
14 |
self.failIf('&' in msgid1) |
|
15 |
self.failIf('=' in msgid1) |
|
16 |
self.failIf('/' in msgid1) |
|
17 |
self.failIf('+' in msgid1) |
|
18 |
values = parse_message_id(msgid1, 'testapp') |
|
19 |
self.failUnless(values) |
|
20 |
# parse_message_id should work with or without surrounding <> |
|
21 |
self.failUnlessEqual(values, parse_message_id(msgid1[1:-1], 'testapp')) |
|
22 |
self.failUnlessEqual(values['eid'], '21') |
|
23 |
self.failUnless('timestamp' in values) |
|
24 |
self.failUnlessEqual(parse_message_id(msgid1[1:-1], 'anotherapp'), None) |
|
1723 | 25 |
|
0 | 26 |
def test_notimestamp(self): |
27 |
msgid1 = construct_message_id('testapp', 21, False) |
|
28 |
msgid2 = construct_message_id('testapp', 21, False) |
|
29 |
values = parse_message_id(msgid1, 'testapp') |
|
30 |
self.failUnlessEqual(values, {'eid': '21'}) |
|
31 |
||
32 |
def test_parse_message_doesnt_raise(self): |
|
33 |
self.failUnlessEqual(parse_message_id('oijioj@bla.bla', 'tesapp'), None) |
|
34 |
self.failUnlessEqual(parse_message_id('oijioj@bla', 'tesapp'), None) |
|
35 |
self.failUnlessEqual(parse_message_id('oijioj', 'tesapp'), None) |
|
36 |
||
37 |
||
38 |
def test_nonregr_empty_message_id(self): |
|
39 |
for eid in (1, 12, 123, 1234): |
|
40 |
msgid1 = construct_message_id('testapp', eid, 12) |
|
41 |
self.assertNotEquals(msgid1, '<@testapp.%s>' % gethostname()) |
|
1723 | 42 |
|
0 | 43 |
|
44 |
class RecipientsFinderTC(EnvBasedTC): |
|
45 |
def test(self): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
46 |
urset = self.execute('CWUser X WHERE X login "admin"') |
0 | 47 |
self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X ' |
48 |
'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
|
49 |
self.execute('INSERT CWProperty X: X pkey "ui.language", X value "fr", X for_user U ' |
0 | 50 |
'WHERE U eid %(x)s', {'x': urset[0][0]}) |
51 |
self.commit() # commit so that admin get its properties updated |
|
52 |
finder = self.vreg.select_component('recipients_finder', self.request(), urset) |
|
53 |
self.set_option('default-recipients-mode', 'none') |
|
54 |
self.assertEquals(finder.recipients(), []) |
|
55 |
self.set_option('default-recipients-mode', 'users') |
|
56 |
self.assertEquals(finder.recipients(), [(u'admin@logilab.fr', 'fr')]) |
|
57 |
self.set_option('default-recipients-mode', 'default-dest-addrs') |
|
58 |
self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr') |
|
59 |
self.assertEquals(finder.recipients(), [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')]) |
|
1723 | 60 |
|
0 | 61 |
|
62 |
class StatusChangeViewsTC(EnvBasedTC): |
|
1723 | 63 |
|
0 | 64 |
def test_status_change_view(self): |
65 |
req = self.session() |
|
66 |
u = self.create_user('toto', req=req) |
|
67 |
assert u.req |
|
68 |
self.execute('SET X in_state S WHERE X eid %s, S name "deactivated"' % u.eid) |
|
69 |
v = self.vreg.select_view('notif_status_change', req, u.rset, row=0) |
|
1723 | 70 |
content = v.render(row=0, comment='yeah', |
71 |
previous_state='activated', |
|
72 |
current_state='deactivated') |
|
0 | 73 |
# remove date |
74 |
self.assertEquals(content, |
|
75 |
''' |
|
76 |
admin changed status from <activated> to <deactivated> for entity |
|
77 |
'toto' |
|
78 |
||
79 |
yeah |
|
80 |
||
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
81 |
url: http://testing.fr/cubicweb/cwuser/toto |
0 | 82 |
''') |
1902
d38a46498eb9
[test] fix tests after renaming e{user,group} to cw{user,group}
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1723
diff
changeset
|
83 |
self.assertEquals(v.subject(), 'status changed cwuser #%s (admin)' % u.eid) |
0 | 84 |
|
85 |
if __name__ == '__main__': |
|
86 |
unittest_main() |