sobjects/test/unittest_notification.py
changeset 9745 c013d5d76f66
parent 9675 8aabfefc8a81
child 11011 94bbf6d7eaf8
equal deleted inserted replaced
9744:4693bf7ffb68 9745:c013d5d76f66
     1 # -*- coding: iso-8859-1 -*-
     1 # -*- coding: iso-8859-1 -*-
     2 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     4 #
     4 #
     5 # This file is part of CubicWeb.
     5 # This file is part of CubicWeb.
     6 #
     6 #
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
    14 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    15 # details.
    15 # details.
    16 #
    16 #
    17 # You should have received a copy of the GNU Lesser General Public License along
    17 # You should have received a copy of the GNU Lesser General Public License along
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    19 """
       
    20 
    19 
    21 """
       
    22 from socket import gethostname
    20 from socket import gethostname
    23 
    21 
    24 from logilab.common.testlib import unittest_main, TestCase
    22 from logilab.common.testlib import unittest_main, TestCase
    25 from cubicweb.devtools.testlib import CubicWebTC, MAILBOX
    23 from cubicweb.devtools.testlib import CubicWebTC, MAILBOX
    26 
    24 
    61             self.assertNotEqual(msgid1, '<@testapp.%s>' % gethostname())
    59             self.assertNotEqual(msgid1, '<@testapp.%s>' % gethostname())
    62 
    60 
    63 class NotificationTC(CubicWebTC):
    61 class NotificationTC(CubicWebTC):
    64 
    62 
    65     def test_recipients_finder(self):
    63     def test_recipients_finder(self):
    66         urset = self.execute('CWUser X WHERE X login "admin"')
    64         with self.admin_access.web_request() as req:
    67         self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X '
    65             urset = req.execute('CWUser X WHERE X login "admin"')
    68                      'WHERE U eid %(x)s', {'x': urset[0][0]})
    66             req.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X '
    69         self.execute('INSERT CWProperty X: X pkey "ui.language", X value "fr", X for_user U '
    67                         'WHERE U eid %(x)s', {'x': urset[0][0]})
    70                      'WHERE U eid %(x)s', {'x': urset[0][0]})
    68             req.execute('INSERT CWProperty X: X pkey "ui.language", X value "fr", X for_user U '
    71         self.commit() # commit so that admin get its properties updated
    69                         'WHERE U eid %(x)s', {'x': urset[0][0]})
    72         finder = self.vreg['components'].select('recipients_finder',
    70             req.cnx.commit() # commit so that admin get its properties updated
    73                                                 self.request(), rset=urset)
    71             finder = self.vreg['components'].select('recipients_finder',
    74         self.set_option('default-recipients-mode', 'none')
    72                                                     req, rset=urset)
    75         self.assertEqual(finder.recipients(), [])
    73             self.set_option('default-recipients-mode', 'none')
    76         self.set_option('default-recipients-mode', 'users')
    74             self.assertEqual(finder.recipients(), [])
    77         self.assertEqual(finder.recipients(), [(u'admin@logilab.fr', 'fr')])
    75             self.set_option('default-recipients-mode', 'users')
    78         self.set_option('default-recipients-mode', 'default-dest-addrs')
    76             self.assertEqual(finder.recipients(), [(u'admin@logilab.fr', 'fr')])
    79         self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr')
    77             self.set_option('default-recipients-mode', 'default-dest-addrs')
    80         self.assertEqual(finder.recipients(), [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')])
    78             self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr')
       
    79             self.assertEqual(finder.recipients(), [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')])
    81 
    80 
    82     def test_status_change_view(self):
    81     def test_status_change_view(self):
    83         req = self.request()
    82         with self.admin_access.web_request() as req:
    84         u = self.create_user(req, 'toto')
    83             u = self.create_user(req, 'toto')
    85         iwfable = u.cw_adapt_to('IWorkflowable')
    84             iwfable = u.cw_adapt_to('IWorkflowable')
    86         iwfable.fire_transition('deactivate', comment=u'yeah')
    85             iwfable.fire_transition('deactivate', comment=u'yeah')
    87         self.assertFalse(MAILBOX)
    86             self.assertFalse(MAILBOX)
    88         self.commit()
    87             req.cnx.commit()
    89         self.assertEqual(len(MAILBOX), 1)
    88             self.assertEqual(len(MAILBOX), 1)
    90         email = MAILBOX[0]
    89             email = MAILBOX[0]
    91         self.assertEqual(email.content,
    90             self.assertEqual(email.content,
    92                           '''
    91                              '''
    93 admin changed status from <activated> to <deactivated> for entity
    92 admin changed status from <activated> to <deactivated> for entity
    94 'toto'
    93 'toto'
    95 
    94 
    96 yeah
    95 yeah
    97 
    96 
    98 url: http://testing.fr/cubicweb/cwuser/toto
    97 url: http://testing.fr/cubicweb/cwuser/toto
    99 ''')
    98 ''')
   100         self.assertEqual(email.subject,
    99             self.assertEqual(email.subject,
   101                          'status changed CWUser #%s (admin)' % u.eid)
   100                              'status changed CWUser #%s (admin)' % u.eid)
   102 
   101 
   103 if __name__ == '__main__':
   102 if __name__ == '__main__':
   104     unittest_main()
   103     unittest_main()