test/unittest_repoapi.py
changeset 10356 a009a31fb1ea
parent 10354 635cfac73d28
equal deleted inserted replaced
10355:60b8204fcca3 10356:a009a31fb1ea
    24 from cubicweb.repoapi import Connection, connect, anonymous_cnx
    24 from cubicweb.repoapi import Connection, connect, anonymous_cnx
    25 
    25 
    26 
    26 
    27 class REPOAPITC(CubicWebTC):
    27 class REPOAPITC(CubicWebTC):
    28 
    28 
    29     def test_clt_cnx_basic_usage(self):
    29     def test_cnx_basic_usage(self):
    30         """Test that a client connection can be used to access the database"""
    30         """Test that a client connection can be used to access the database"""
    31         with self.admin_access.client_cnx() as cltcnx:
    31         with self.admin_access.client_cnx() as cltcnx:
    32             # (1) some RQL request
    32             # (1) some RQL request
    33             rset = cltcnx.execute('Any X WHERE X is CWUser')
    33             rset = cltcnx.execute('Any X WHERE X is CWUser')
    34             self.assertTrue(rset)
    34             self.assertTrue(rset)
    50             rset = cltcnx.execute('''Any X WHERE X is CWUser,
    50             rset = cltcnx.execute('''Any X WHERE X is CWUser,
    51                                                  X surname "babar"
    51                                                  X surname "babar"
    52                                   ''')
    52                                   ''')
    53             self.assertTrue(rset)
    53             self.assertTrue(rset)
    54 
    54 
    55     def test_clt_cnx_life_cycle(self):
    55     def test_cnx_life_cycle(self):
    56         """Check that ClientConnection requires explicit open and close
    56         """Check that ClientConnection requires explicit open and close
    57         """
    57         """
    58         access = self.admin_access
    58         access = self.admin_access
    59         cltcnx = Connection(access._session)
    59         cltcnx = Connection(access._session)
    60         # connection not open yet
    60         # connection not open yet
    67         with self.assertRaises(ProgrammingError):
    67         with self.assertRaises(ProgrammingError):
    68             cltcnx.execute('Any X WHERE X is CWUser')
    68             cltcnx.execute('Any X WHERE X is CWUser')
    69 
    69 
    70     def test_connect(self):
    70     def test_connect(self):
    71         """check that repoapi.connect works and returns a usable connection"""
    71         """check that repoapi.connect works and returns a usable connection"""
    72         clt_cnx = connect(self.repo, login='admin', password='gingkow')
    72         cnx = connect(self.repo, login='admin', password='gingkow')
    73         self.assertEqual('admin', clt_cnx.user.login)
    73         self.assertEqual('admin', cnx.user.login)
    74         with clt_cnx:
    74         with cnx:
    75             rset = clt_cnx.execute('Any X WHERE X is CWUser')
    75             rset = cnx.execute('Any X WHERE X is CWUser')
    76             self.assertTrue(rset)
    76             self.assertTrue(rset)
    77 
    77 
    78     def test_anonymous_connect(self):
    78     def test_anonymous_connect(self):
    79         """check that you can get anonymous connection when the data exist"""
    79         """check that you can get anonymous connection when the data exist"""
    80         clt_cnx = anonymous_cnx(self.repo)
    80         cnx = anonymous_cnx(self.repo)
    81         self.assertEqual('anon', clt_cnx.user.login)
    81         self.assertEqual('anon', cnx.user.login)
    82         with clt_cnx:
    82         with cnx:
    83             rset = clt_cnx.execute('Any X WHERE X is CWUser')
    83             rset = cnx.execute('Any X WHERE X is CWUser')
    84             self.assertTrue(rset)
    84             self.assertTrue(rset)
    85 
    85 
    86 
    86 
    87 if __name__ == '__main__':
    87 if __name__ == '__main__':
    88     from logilab.common.testlib import unittest_main
    88     from logilab.common.testlib import unittest_main