--- a/dbapi.py Tue Mar 08 17:55:38 2011 +0100
+++ b/dbapi.py Tue Mar 08 18:08:12 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):
--- a/devtools/__init__.py Tue Mar 08 17:55:38 2011 +0100
+++ b/devtools/__init__.py Tue Mar 08 18:08:12 2011 +0100
@@ -217,7 +217,7 @@
def init_test_database(config=None, appid='data', apphome=None):
"""init a test database for a specific driver"""
- from cubicweb.dbapi import in_memory_cnx
+ from cubicweb.dbapi import in_memory_repo_cnx
config = config or TestServerConfiguration(appid, apphome=apphome)
sources = config.sources()
driver = sources['system']['db-driver']
@@ -229,7 +229,7 @@
else:
raise ValueError('no initialization function for driver %r' % driver)
config._cubes = None # avoid assertion error
- repo, cnx = in_memory_cnx(config, unicode(sources['admin']['login']),
+ repo, cnx = in_memory_repo_cnx(config, unicode(sources['admin']['login']),
password=sources['admin']['password'] or 'xxx')
if driver == 'sqlite':
install_sqlite_patch(repo.querier)
--- a/devtools/livetest.py Tue Mar 08 17:55:38 2011 +0100
+++ b/devtools/livetest.py Tue Mar 08 18:08:12 2011 +0100
@@ -35,7 +35,7 @@
from logilab.common.testlib import TestCase
-from cubicweb.dbapi import in_memory_cnx
+from cubicweb.dbapi import in_memory_repo_cnx
from cubicweb.etwist.server import CubicWebRootResource
from cubicweb.devtools import BaseApptestConfiguration, init_test_database
@@ -164,7 +164,7 @@
# build a config, and get a connection
self.config = LivetestConfiguration(self.cube, self.sourcefile)
_, user, passwd, _ = loadconf()
- self.repo, self.cnx = in_memory_cnx(self.config, user, password=passwd)
+ self.repo, self.cnx = in_memory_repo_cnx(self.config, user, password=passwd)
self.setup_db(self.cnx)
def tearDown(self):
--- a/misc/scripts/repair_file_1-9_migration.py Tue Mar 08 17:55:38 2011 +0100
+++ b/misc/scripts/repair_file_1-9_migration.py Tue Mar 08 18:08:12 2011 +0100
@@ -19,9 +19,9 @@
sourcescfg = repo.config.sources()
backupcfg = cwconfig.instance_configuration(backupinstance)
backupcfg.repairing = True
-backuprepo, backupcnx = dbapi.in_memory_cnx(backupcfg, sourcescfg['admin']['login'],
- password=sourcescfg['admin']['password'],
- host='localhost')
+backuprepo, backupcnx = dbapi.in_memory_repo_cnx(backupcfg, sourcescfg['admin']['login'],
+ password=sourcescfg['admin']['password'],
+ host='localhost')
backupcu = backupcnx.cursor()
with hooks_control(session, session.HOOKS_DENY_ALL):
--- a/server/__init__.py Tue Mar 08 17:55:38 2011 +0100
+++ b/server/__init__.py Tue Mar 08 18:08:12 2011 +0100
@@ -121,7 +121,7 @@
with the minimal set of entities (ie at least the schema, base groups and
a initial user)
"""
- from cubicweb.dbapi import in_memory_cnx
+ from cubicweb.dbapi import in_memory_repo_cnx
from cubicweb.server.repository import Repository
from cubicweb.server.utils import manager_userpasswd
from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema
@@ -185,7 +185,7 @@
repo.shutdown()
# reloging using the admin user
config._cubes = None # avoid assertion error
- repo, cnx = in_memory_cnx(config, login, password=pwd)
+ repo, cnx = in_memory_repo_cnx(config, login, password=pwd)
repo.system_source.eid = ssource.eid # redo this manually
# trigger vreg initialisation of entity classes
config.cubicweb_appobject_path = set(('entities',))
--- a/server/serverctl.py Tue Mar 08 17:55:38 2011 +0100
+++ b/server/serverctl.py Tue Mar 08 18:08:12 2011 +0100
@@ -130,7 +130,7 @@
def repo_cnx(config):
"""return a in-memory repository and a db api connection it"""
- from cubicweb.dbapi import in_memory_cnx
+ from cubicweb.dbapi import in_memory_repo_cnx
from cubicweb.server.utils import manager_userpasswd
try:
login = config.sources()['admin']['login']
@@ -139,7 +139,7 @@
login, pwd = manager_userpasswd()
while True:
try:
- return in_memory_cnx(config, login, password=pwd)
+ return in_memory_repo_cnx(config, login, password=pwd)
except AuthenticationError:
print '-> Error: wrong user/password.'
# reset cubes else we'll have an assertion error on next retry