test/unittest_dbapi.py
changeset 8366 6599f69bb846
parent 7554 fdace9d67d96
child 8367 fc59d2380c48
equal deleted inserted replaced
8365:51c390500c63 8366:6599f69bb846
    21 
    21 
    22 from copy import copy
    22 from copy import copy
    23 
    23 
    24 from logilab.common import tempattr
    24 from logilab.common import tempattr
    25 
    25 
    26 from cubicweb import ConnectionError, cwconfig
    26 from cubicweb import ConnectionError, cwconfig, NoSelectableObject
    27 from cubicweb.dbapi import ProgrammingError
    27 from cubicweb.dbapi import ProgrammingError
    28 from cubicweb.devtools.testlib import CubicWebTC
    28 from cubicweb.devtools.testlib import CubicWebTC
       
    29 
    29 
    30 
    30 class DBAPITC(CubicWebTC):
    31 class DBAPITC(CubicWebTC):
    31 
    32 
    32     def test_public_repo_api(self):
    33     def test_public_repo_api(self):
    33         cnx = self.login('anon')
    34         cnx = self.login('anon')
    80             self.assertEqual(req.from_controller(), 'view')
    81             self.assertEqual(req.from_controller(), 'view')
    81             self.assertEqual(req.relative_path(), '')
    82             self.assertEqual(req.relative_path(), '')
    82             req.ajax_replace_url('domid') # don't crash
    83             req.ajax_replace_url('domid') # don't crash
    83             req.user.cw_adapt_to('IBreadCrumbs') # don't crash
    84             req.user.cw_adapt_to('IBreadCrumbs') # don't crash
    84 
    85 
       
    86     def test_call_service(self):
       
    87         req = self.request()
       
    88         ServiceClass = self.vreg['services']['test_service'][0]
       
    89         ret_value = req.cnx.call_service('test_service', msg='coucou')
       
    90         self.assertEqual('coucou', ServiceClass.passed_here.pop())
       
    91         self.assertEqual('babar', ret_value)
       
    92         with self.login('anon') as ctm:
       
    93             with self.assertRaises(NoSelectableObject):
       
    94                 self.request().cnx.call_service('test_service', msg='toto')
       
    95             self.rollback()
       
    96             self.assertEqual([], ServiceClass.passed_here)
       
    97 
       
    98 
    85 if __name__ == '__main__':
    99 if __name__ == '__main__':
    86     from logilab.common.testlib import unittest_main
   100     from logilab.common.testlib import unittest_main
    87     unittest_main()
   101     unittest_main()