[connection] eliminate ClientConnection leftovers
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 13 Jun 2014 15:56:08 +0200
changeset 10356 a009a31fb1ea
parent 10355 60b8204fcca3
child 10357 59a79300f213
[connection] eliminate ClientConnection leftovers * in the documentation * in the docstrings * in code notations (e.g. clt_cnx -> cnx) Related to #3837233. From now, there should be just one ClientConnection left in repoapi.py.
devtools/testlib.py
doc/book/en/devweb/request.rst
repoapi.py
server/sources/native.py
test/unittest_repoapi.py
web/test/unittest_application.py
--- a/devtools/testlib.py	Fri Jun 13 15:42:04 2014 +0200
+++ b/devtools/testlib.py	Fri Jun 13 15:56:08 2014 +0200
@@ -157,7 +157,7 @@
 
 
 class TestCaseConnectionProxy(object):
-    """thin wrapper around `cubicweb.repoapi.ClientConnection` context-manager
+    """thin wrapper around `cubicweb.repoapi.Connection` context-manager
     used in CubicWebTC (cf. `cubicweb.devtools.testlib.CubicWebTC.login` method)
 
     It just proxies to the default connection context manager but
@@ -299,9 +299,9 @@
 
     def __init__(self, *args, **kwargs):
         self._admin_session = None
-        self._admin_clt_cnx = None
+        self._admin_cnx = None
         self._current_session = None
-        self._current_clt_cnx = None
+        self._current_cnx = None
         self.repo = None
         self._open_access = set()
         super(CubicWebTC, self).__init__(*args, **kwargs)
@@ -327,21 +327,21 @@
     @deprecated('[3.19] explicitly use RepoAccess object in test instead')
     def set_cnx(self, cnx):
         assert getattr(cnx, '_session', None) is not None
-        if cnx is self._admin_clt_cnx:
+        if cnx is self._admin_cnx:
             self._pop_custom_cnx()
         else:
             self._cnxs.add(cnx) # register the cnx to make sure it is removed
             self._current_session = cnx.session
-            self._current_clt_cnx = cnx
+            self._current_cnx = cnx
 
     @property
     @deprecated('[3.19] explicitly use RepoAccess object in test instead')
     def cnx(self):
         # XXX we want to deprecate this
-        clt_cnx = self._current_clt_cnx
-        if clt_cnx is None:
-            clt_cnx = self._admin_clt_cnx
-        return clt_cnx
+        cnx = self._current_cnx
+        if cnx is None:
+            cnx = self._admin_cnx
+        return cnx
 
     def _close_cnx(self):
         """ensure that all cnx used by a test have been closed"""
@@ -380,22 +380,22 @@
         else:
             if not kwargs:
                 kwargs['password'] = str(login)
-            clt_cnx = repoapi.connect(self.repo, login, **kwargs)
-        self.set_cnx(clt_cnx)
-        clt_cnx.__enter__()
-        return TestCaseConnectionProxy(self, clt_cnx)
+            cnx = repoapi.connect(self.repo, login, **kwargs)
+        self.set_cnx(cnx)
+        cnx.__enter__()
+        return TestCaseConnectionProxy(self, cnx)
 
     @deprecated('[3.19] explicitly use RepoAccess object in test instead')
     def restore_connection(self):
         self._pop_custom_cnx()
 
     def _pop_custom_cnx(self):
-        if self._current_clt_cnx is not None:
-            if self._current_clt_cnx._open:
-                self._current_clt_cnx.close()
+        if self._current_cnx is not None:
+            if self._current_cnx._open:
+                self._current_cnx.close()
             if not  self._current_session.closed:
                 self.repo.close(self._current_session.sessionid)
-            self._current_clt_cnx = None
+            self._current_cnx = None
             self._current_session = None
 
     #XXX this doesn't need to a be classmethod anymore
@@ -411,9 +411,9 @@
         login = unicode(db_handler.config.default_admin_config['login'])
         self.admin_access = self.new_access(login)
         self._admin_session = self.admin_access._session
-        self._admin_clt_cnx = repoapi.Connection(self._admin_session)
-        self._cnxs.add(self._admin_clt_cnx)
-        self._admin_clt_cnx.__enter__()
+        self._admin_cnx = repoapi.Connection(self._admin_session)
+        self._cnxs.add(self._admin_cnx)
+        self._admin_cnx.__enter__()
         self.config.repository = lambda x=None: self.repo
 
 
@@ -517,13 +517,13 @@
                 raise
             self.addCleanup(self._close_access)
         self.setup_database()
-        self._admin_clt_cnx.commit()
+        self._admin_cnx.commit()
         MAILBOX[:] = [] # reset mailbox
 
     def tearDown(self):
         # XXX hack until logilab.common.testlib is fixed
-        if self._admin_clt_cnx is not None:
-            self._admin_clt_cnx = None
+        if self._admin_cnx is not None:
+            self._admin_cnx = None
         if self._admin_session is not None:
             self.repo.close(self._admin_session.sessionid)
             self._admin_session = None
@@ -573,9 +573,7 @@
                 groups = login
             elif isinstance(login, tuple):
                 groups = login
-            login = req
-            assert not isinstance(self, type)
-            req = self._admin_clt_cnx
+                req = self._admin_cnx
         if login is not None:
             login = unicode(login)
         if password is None:
@@ -969,8 +967,8 @@
     def assertAuthSuccess(self, req, origsession, nbsessions=1):
         sh = self.app.session_handler
         session = self.app.get_session(req)
-        clt_cnx = repoapi.Connection(session)
-        req.set_cnx(clt_cnx)
+        cnx = repoapi.Connection(session)
+        req.set_cnx(cnx)
         self.assertEqual(len(self.open_sessions), nbsessions, self.open_sessions)
         self.assertEqual(session.login, origsession.login)
         self.assertEqual(session.anonymous_session, False)
--- a/doc/book/en/devweb/request.rst	Fri Jun 13 15:42:04 2014 +0200
+++ b/doc/book/en/devweb/request.rst	Fri Jun 13 15:56:08 2014 +0200
@@ -118,13 +118,13 @@
 ```
 
 The elements we gave in overview for above are built in three layers,
-from ``cubicweb.req.RequestSessionBase``, ``cubicweb.repoapi.ClientConnection`` and
+from ``cubicweb.req.RequestSessionBase``, ``cubicweb.repoapi.Connection`` and
 ``cubicweb.web.ConnectionCubicWebRequestBase``.
 
 .. autoclass:: cubicweb.req.RequestSessionBase
    :members:
 
-.. autoclass:: cubicweb.repoapi.ClientConnection
+.. autoclass:: cubicweb.repoapi.Connection
    :members:
 
 .. autoclass:: cubicweb.web.request.ConnectionCubicWebRequestBase
--- a/repoapi.py	Fri Jun 13 15:42:04 2014 +0200
+++ b/repoapi.py	Fri Jun 13 15:56:08 2014 +0200
@@ -53,10 +53,7 @@
     raise ConnectionError('unknown protocol: `%s`' % protocol)
 
 def connect(repo, login, **kwargs):
-    """Take credential and return associated ClientConnection.
-
-    The ClientConnection is associated to a new Session object that will be
-    closed when the ClientConnection is closed.
+    """Take credential and return associated Connection.
 
     raise AuthenticationError if the credential are invalid."""
     sessionid = repo.connect(login, **kwargs)
@@ -66,10 +63,7 @@
     return Connection(session)
 
 def anonymous_cnx(repo):
-    """return a ClientConnection for Anonymous user.
-
-    The ClientConnection is associated to a new Session object that will be
-    closed when the ClientConnection is closed.
+    """return a Connection for Anonymous user.
 
     raises an AuthenticationError if anonymous usage is not allowed
     """
--- a/server/sources/native.py	Fri Jun 13 15:42:04 2014 +0200
+++ b/server/sources/native.py	Fri Jun 13 15:56:08 2014 +0200
@@ -952,7 +952,7 @@
     # undo support #############################################################
 
     def undoable_transactions(self, cnx, ueid=None, **actionfilters):
-        """See :class:`cubicweb.repoapi.ClientConnection.undoable_transactions`"""
+        """See :class:`cubicweb.repoapi.Connection.undoable_transactions`"""
         # force filtering to connection's user if not a manager
         if not cnx.user.is_in_group('managers'):
             ueid = cnx.user.eid
@@ -1025,11 +1025,11 @@
             return [tx.Transaction(*args) for args in cu.fetchall()]
 
     def tx_info(self, cnx, txuuid):
-        """See :class:`cubicweb.repoapi.ClientConnection.transaction_info`"""
+        """See :class:`cubicweb.repoapi.Connection.transaction_info`"""
         return tx.Transaction(txuuid, *self._tx_info(cnx, unicode(txuuid)))
 
     def tx_actions(self, cnx, txuuid, public):
-        """See :class:`cubicweb.repoapi.ClientConnection.transaction_actions`"""
+        """See :class:`cubicweb.repoapi.Connection.transaction_actions`"""
         txuuid = unicode(txuuid)
         self._tx_info(cnx, txuuid)
         restr = {'tx_uuid': txuuid}
@@ -1052,7 +1052,7 @@
         return sorted(actions, key=lambda x: x.order)
 
     def undo_transaction(self, cnx, txuuid):
-        """See :class:`cubicweb.repoapi.ClientConnection.undo_transaction`
+        """See :class:`cubicweb.repoapi.Connection.undo_transaction`
 
         important note: while undoing of a transaction, only hooks in the
         'integrity', 'activeintegrity' and 'undo' categories are called.
--- a/test/unittest_repoapi.py	Fri Jun 13 15:42:04 2014 +0200
+++ b/test/unittest_repoapi.py	Fri Jun 13 15:56:08 2014 +0200
@@ -26,7 +26,7 @@
 
 class REPOAPITC(CubicWebTC):
 
-    def test_clt_cnx_basic_usage(self):
+    def test_cnx_basic_usage(self):
         """Test that a client connection can be used to access the database"""
         with self.admin_access.client_cnx() as cltcnx:
             # (1) some RQL request
@@ -52,7 +52,7 @@
                                   ''')
             self.assertTrue(rset)
 
-    def test_clt_cnx_life_cycle(self):
+    def test_cnx_life_cycle(self):
         """Check that ClientConnection requires explicit open and close
         """
         access = self.admin_access
@@ -69,18 +69,18 @@
 
     def test_connect(self):
         """check that repoapi.connect works and returns a usable connection"""
-        clt_cnx = connect(self.repo, login='admin', password='gingkow')
-        self.assertEqual('admin', clt_cnx.user.login)
-        with clt_cnx:
-            rset = clt_cnx.execute('Any X WHERE X is CWUser')
+        cnx = connect(self.repo, login='admin', password='gingkow')
+        self.assertEqual('admin', cnx.user.login)
+        with cnx:
+            rset = cnx.execute('Any X WHERE X is CWUser')
             self.assertTrue(rset)
 
     def test_anonymous_connect(self):
         """check that you can get anonymous connection when the data exist"""
-        clt_cnx = anonymous_cnx(self.repo)
-        self.assertEqual('anon', clt_cnx.user.login)
-        with clt_cnx:
-            rset = clt_cnx.execute('Any X WHERE X is CWUser')
+        cnx = anonymous_cnx(self.repo)
+        self.assertEqual('anon', cnx.user.login)
+        with cnx:
+            rset = cnx.execute('Any X WHERE X is CWUser')
             self.assertTrue(rset)
 
 
--- a/web/test/unittest_application.py	Fri Jun 13 15:42:04 2014 +0200
+++ b/web/test/unittest_application.py	Fri Jun 13 15:56:08 2014 +0200
@@ -371,7 +371,7 @@
     def _test_auth_anon(self, req):
         asession = self.app.get_session(req)
         # important otherwise _reset_cookie will not use the right session
-        req.set_cnx(repoapi.ClientConnection(asession))
+        req.set_cnx(repoapi.Connection(asession))
         self.assertEqual(len(self.open_sessions), 1)
         self.assertEqual(asession.login, 'anon')
         self.assertTrue(asession.anonymous_session)
@@ -381,7 +381,7 @@
         self.assertEqual(1, len(self.open_sessions))
         session = self.app.get_session(req)
         # important otherwise _reset_cookie will not use the right session
-        req.set_cnx(repoapi.ClientConnection(session))
+        req.set_cnx(repoapi.Connection(session))
         self.assertEqual(req.message, 'authentication failure')
         self.assertEqual(req.session.anonymous_session, True)
         self.assertEqual(1, len(self.open_sessions))