[session] add a new_cnx factory
Having user-code importing cubicweb.server.session.Connection is inconvenient.
We add a simple factory fonction on the session.
--- a/server/session.py Wed Jun 26 14:26:06 2013 +0200
+++ b/server/session.py Wed Jun 26 14:46:24 2013 +0200
@@ -1315,6 +1315,13 @@
# XXX backward compat with dbapi. deprecate me ASAP.
return self.user.login
+ def new_cnx(self):
+ """Return a new Connection object linked to the session
+
+ The returned Connection will *not* be managed by the Session.
+ """
+ return Connection(self)
+
def get_cnx(self, cnxid):
"""return the <cnxid> connection attached to this session
--- a/server/test/unittest_session.py Wed Jun 26 14:26:06 2013 +0200
+++ b/server/test/unittest_session.py Wed Jun 26 14:46:24 2013 +0200
@@ -68,7 +68,7 @@
self.assertEqual(set(), session.enabled_hook_categories)
def test_explicite_connection(self):
- with Connection(self.session) as cnx:
+ with self.session.new_cnx() as cnx:
rset = cnx.execute('Any X LIMIT 1 WHERE X is CWUser')
self.assertEqual(1, len(rset))
user = rset.get_entity(0, 0)