# HG changeset patch # User Aurelien Campeas # Date 1401464800 -7200 # Node ID 4e640ab62f51b34c6eb1cbcdecc4ac38c0a3fe98 # Parent 2d1e488f6f714412a7efeb1f9d325e92c5438df2 [tests/checkintegrity] use the new connection api * serverctl: the db-check command also uses an internal connection object, which makes more sense in the context of `checkintegrity`. * checkintegrity: rename srvcnx to just cnx (a bit because in the near future, there will be one cnx to rule them all) diff -r 2d1e488f6f71 -r 4e640ab62f51 server/checkintegrity.py --- a/server/checkintegrity.py Fri May 30 17:40:22 2014 +0200 +++ b/server/checkintegrity.py Fri May 30 17:46:40 2014 +0200 @@ -1,4 +1,4 @@ -# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of CubicWeb. @@ -395,22 +395,21 @@ (no running cubicweb server needed) """ # yo, launch checks - srvcnx = cnx._cnx if checks: eids_cache = {} - with srvcnx.security_enabled(read=False, write=False): # ensure no read security + with cnx.security_enabled(read=False, write=False): # ensure no read security for check in checks: check_func = globals()['check_%s' % check] - with srvcnx.ensure_cnx_set: - check_func(repo.schema, srvcnx, eids_cache, fix=fix) + with cnx.ensure_cnx_set: + check_func(repo.schema, cnx, eids_cache, fix=fix) if fix: - srvcnx.commit() + cnx.commit() else: print if not fix: print 'WARNING: Diagnostic run, nothing has been corrected' if reindex: - srvcnx.rollback() - with srvcnx.ensure_cnx_set: - reindex_entities(repo.schema, srvcnx, withpb=withpb) - srvcnx.commit() + cnx.rollback() + with cnx.ensure_cnx_set: + reindex_entities(repo.schema, cnx, withpb=withpb) + cnx.commit() diff -r 2d1e488f6f71 -r 4e640ab62f51 server/serverctl.py --- a/server/serverctl.py Fri May 30 17:40:22 2014 +0200 +++ b/server/serverctl.py Fri May 30 17:46:40 2014 +0200 @@ -1,4 +1,4 @@ -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of CubicWeb. @@ -979,10 +979,12 @@ appid = args[0] config = ServerConfiguration.config_for(appid) config.repairing = self.config.force - repo, cnx = repo_cnx(config) - with cnx: + repo, _cnx = repo_cnx(config) + with repo.internal_cnx() as cnx: check(repo, cnx, - self.config.checks, self.config.reindex, self.config.autofix) + self.config.checks, + self.config.reindex, + self.config.autofix) class RebuildFTICommand(Command): diff -r 2d1e488f6f71 -r 4e640ab62f51 server/test/unittest_checkintegrity.py --- a/server/test/unittest_checkintegrity.py Fri May 30 17:40:22 2014 +0200 +++ b/server/test/unittest_checkintegrity.py Fri May 30 17:46:40 2014 +0200 @@ -1,4 +1,4 @@ -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of CubicWeb. @@ -25,41 +25,40 @@ from cubicweb.server.checkintegrity import check, reindex_entities class CheckIntegrityTC(TestCase): + def setUp(self): handler = get_test_db_handler(TestServerConfiguration(apphome=self.datadir)) handler.build_db_cache() - self.repo, self.cnx = handler.get_repo_and_cnx() - session = self.repo._get_session(self.cnx.sessionid, setcnxset=True) - self.session = session - self.execute = session.execute + self.repo, _cnx = handler.get_repo_and_cnx() sys.stderr = sys.stdout = StringIO() def tearDown(self): sys.stderr = sys.__stderr__ sys.stdout = sys.__stdout__ - self.cnx.close() self.repo.shutdown() def test_checks(self): - with self.cnx: - check(self.repo, self.cnx, ('entities', 'relations', 'text_index', 'metadata'), + with self.repo.internal_cnx() as cnx: + check(self.repo, 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"') - self.session.commit(False) - self.assertTrue(self.execute('Any X WHERE X has_text "tutu"')) - reindex_entities(self.repo.schema, self.session, withpb=False) - self.assertTrue(self.execute('Any X WHERE X has_text "tutu"')) + with self.repo.internal_cnx() as cnx: + cnx.execute('INSERT Personne X: X nom "toto", X prenom "tutu"') + cnx.commit() + self.assertTrue(cnx.execute('Any X WHERE X has_text "tutu"')) + reindex_entities(self.repo.schema, cnx, withpb=False) + self.assertTrue(cnx.execute('Any X WHERE X has_text "tutu"')) def test_reindex_etype(self): - self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"') - self.execute('INSERT Affaire X: X ref "toto"') - self.session.commit(False) - reindex_entities(self.repo.schema, self.session, withpb=False, - etypes=('Personne',)) - self.assertTrue(self.execute('Any X WHERE X has_text "tutu"')) - self.assertTrue(self.execute('Any X WHERE X has_text "toto"')) + with self.repo.internal_cnx() as cnx: + cnx.execute('INSERT Personne X: X nom "toto", X prenom "tutu"') + cnx.execute('INSERT Affaire X: X ref "toto"') + cnx.commit() + reindex_entities(self.repo.schema, cnx, withpb=False, + etypes=('Personne',)) + self.assertTrue(cnx.execute('Any X WHERE X has_text "tutu"')) + self.assertTrue(cnx.execute('Any X WHERE X has_text "toto"')) if __name__ == '__main__': unittest_main()