# HG changeset patch # User Julien Cristau # Date 1394019337 -3600 # Node ID 5d4f662f5e3179c65d5406ac1759925da311728c # Parent 754904ac4248779b97b1387a8d39ac2bf68f8661 [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). diff -r 754904ac4248 -r 5d4f662f5e31 devtools/__init__.py --- 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): diff -r 754904ac4248 -r 5d4f662f5e31 server/test/unittest_checkintegrity.py --- 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"') diff -r 754904ac4248 -r 5d4f662f5e31 test/unittest_migration.py --- 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__':