dbapi.py
changeset 7061 bb2080547722
parent 7006 d0f635d3a6bb
parent 7056 51f88f13d6f3
child 7085 36e91d19188b
--- a/dbapi.py	Fri Feb 18 15:26:00 2011 +0100
+++ b/dbapi.py	Tue Mar 08 18:32:19 2011 +0100
@@ -201,21 +201,30 @@
     cnx.vreg = vreg
     return cnx
 
-def in_memory_cnx(config, login, **kwargs):
-    """usefull method for testing and scripting to get a dbapi.Connection
-    object connected to an in-memory repository instance
-    """
+def in_memory_repo(config):
+    """Return and in_memory Repository object from a config (or vreg)"""
     if isinstance(config, cwvreg.CubicWebVRegistry):
         vreg = config
         config = None
     else:
         vreg = None
     # get local access to the repository
-    repo = get_repository('inmemory', config=config, vreg=vreg)
-    # connection to the CubicWeb repository
+    return get_repository('inmemory', config=config, vreg=vreg)
+
+def in_memory_cnx(repo, login, **kwargs):
+    """Establish a In memory connection to a <repo> for the user with <login>
+
+    additionel credential might be required"""
     cnxprops = ConnectionProperties('inmemory')
-    cnx = repo_connect(repo, login, cnxprops=cnxprops, **kwargs)
-    return repo, cnx
+    return repo_connect(repo, login, cnxprops=cnxprops, **kwargs)
+
+def in_memory_repo_cnx(config, login, **kwargs):
+    """usefull method for testing and scripting to get a dbapi.Connection
+    object connected to an in-memory repository instance
+    """
+    # connection to the CubicWeb repository
+    repo = in_memory_repo(config)
+    return repo, in_memory_cnx(repo, login, **kwargs)
 
 class _NeedAuthAccessMock(object):
     def __getattribute__(self, attr):