[devtools] make get_repo_and_cnx return a repoapi ClientConnection
And adjust callers accordingly (they need to use it as a context manager to
open/close it properly).
--- a/devtools/__init__.py Wed Mar 05 11:22:20 2014 +0100
+++ b/devtools/__init__.py Wed Mar 05 12:35:37 2014 +0100
@@ -402,12 +402,12 @@
def get_cnx(self):
"""return Connection object on the current repository"""
- from cubicweb.dbapi import _repo_connect
+ from cubicweb.repoapi import connect
repo = self.get_repo()
sources = self.config.read_sources_file()
login = unicode(sources['admin']['login'])
password = sources['admin']['password'] or 'xxx'
- cnx = _repo_connect(repo, login, password=password)
+ cnx = connect(repo, login, password=password)
return cnx
def get_repo_and_cnx(self, db_id=DEFAULT_EMPTY_DB_ID):
--- a/server/test/unittest_checkintegrity.py Wed Mar 05 11:22:20 2014 +0100
+++ b/server/test/unittest_checkintegrity.py Wed Mar 05 12:35:37 2014 +0100
@@ -41,8 +41,9 @@
self.repo.shutdown()
def test_checks(self):
- check(self.repo, self.cnx, ('entities', 'relations', 'text_index', 'metadata'),
- reindex=False, fix=True, withpb=False)
+ with self.cnx:
+ check(self.repo, self.cnx, ('entities', 'relations', 'text_index', 'metadata'),
+ reindex=False, fix=True, withpb=False)
def test_reindex_all(self):
self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')
--- a/test/unittest_migration.py Wed Mar 05 11:22:20 2014 +0100
+++ b/test/unittest_migration.py Wed Mar 05 12:35:37 2014 +0100
@@ -105,10 +105,9 @@
handler.init_test_database()
handler.build_db_cache()
repo, cnx = handler.get_repo_and_cnx()
- cu = cnx.cursor()
- self.assertEqual(cu.execute('Any SN WHERE X is CWUser, X login "admin", X in_state S, S name SN').rows,
- [['activated']])
- cnx.close()
+ with cnx:
+ self.assertEqual(cnx.execute('Any SN WHERE X is CWUser, X login "admin", X in_state S, S name SN').rows,
+ [['activated']])
repo.shutdown()
if __name__ == '__main__':