[session] raise proper exception with get_tx is called on a closed session
Prevent attribute error on _txs
Closes #2897836
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""cubicweb.migration unit tests"""fromos.pathimportabspath,dirname,joinfromlogilab.common.testlibimportTestCase,unittest_mainfromcubicweb.devtoolsimportTestServerConfigurationfromcubicweb.cwconfigimportCubicWebConfigurationfromcubicweb.migrationimportMigrationHelper,filter_scriptsfromcubicweb.server.migractionsimportServerMigrationHelperclassSchema(dict):defhas_entity(self,e_type):returne_typeinselfSMIGRDIR=join(dirname(__file__),'data','server_migration')+'/'TMIGRDIR=join(dirname(__file__),'data','migration')+'/'classMigrTestConfig(TestServerConfiguration):verbosity=0defmigration_scripts_dir(cls):returnSMIGRDIRdefcube_migration_scripts_dir(cls,cube):returnTMIGRDIRclassMigrationToolsTC(TestCase):defsetUp(self):self.config=MigrTestConfig('data')fromyams.schemaimportSchemaself.config.load_schema=lambdaexpand_cubes=False:Schema('test')self.config.__class__.cubicweb_appobject_path=frozenset()self.config.__class__.cube_appobject_path=frozenset()deftest_filter_scripts_base(self):self.assertListEqual(filter_scripts(self.config,SMIGRDIR,(2,3,0),(2,4,0)),[])self.assertListEqual(filter_scripts(self.config,SMIGRDIR,(2,4,0),(2,5,0)),[((2,5,0),SMIGRDIR+'2.5.0_Any.sql')])self.assertListEqual(filter_scripts(self.config,SMIGRDIR,(2,5,0),(2,6,0)),[((2,6,0),SMIGRDIR+'2.6.0_Any.sql')])self.assertListEqual(filter_scripts(self.config,SMIGRDIR,(2,4,0),(2,6,0)),[((2,5,0),SMIGRDIR+'2.5.0_Any.sql'),((2,6,0),SMIGRDIR+'2.6.0_Any.sql')])self.assertListEqual(filter_scripts(self.config,SMIGRDIR,(2,5,0),(2,5,1)),[])self.assertListEqual(filter_scripts(self.config,SMIGRDIR,(2,5,0),(2,10,2)),[((2,6,0),SMIGRDIR+'2.6.0_Any.sql'),((2,10,2),SMIGRDIR+'2.10.2_Any.sql')])self.assertListEqual(filter_scripts(self.config,SMIGRDIR,(2,5,1),(2,6,0)),[((2,6,0),SMIGRDIR+'2.6.0_Any.sql')])self.assertListEqual(filter_scripts(self.config,TMIGRDIR,(0,0,2),(0,0,3)),[((0,0,3),TMIGRDIR+'0.0.3_Any.py')])self.assertListEqual(filter_scripts(self.config,TMIGRDIR,(0,0,2),(0,0,4)),[((0,0,3),TMIGRDIR+'0.0.3_Any.py'),((0,0,4),TMIGRDIR+'0.0.4_Any.py')])deftest_filter_scripts_for_mode(self):config=CubicWebConfiguration('data')config.verbosity=0self.assert_(notisinstance(config.migration_handler(),ServerMigrationHelper))self.assertIsInstance(config.migration_handler(),MigrationHelper)config=self.configconfig.__class__.name='twisted'self.assertListEqual(filter_scripts(config,TMIGRDIR,(0,0,4),(0,1,0)),[((0,1,0),TMIGRDIR+'0.1.0_common.py'),((0,1,0),TMIGRDIR+'0.1.0_web.py')])config.__class__.name='repository'self.assertListEqual(filter_scripts(config,TMIGRDIR,(0,0,4),(0,1,0)),[((0,1,0),TMIGRDIR+'0.1.0_Any.py'),((0,1,0),TMIGRDIR+'0.1.0_common.py'),((0,1,0),TMIGRDIR+'0.1.0_repository.py')])config.__class__.name='all-in-one'self.assertListEqual(filter_scripts(config,TMIGRDIR,(0,0,4),(0,1,0)),[((0,1,0),TMIGRDIR+'0.1.0_Any.py'),((0,1,0),TMIGRDIR+'0.1.0_common.py'),((0,1,0),TMIGRDIR+'0.1.0_repository.py'),((0,1,0),TMIGRDIR+'0.1.0_web.py')])config.__class__.name='repository'fromcubicweb.devtoolsimportApptestConfiguration,get_test_db_handlerclassBaseCreationTC(TestCase):deftest_db_creation(self):"""make sure database can be created"""config=ApptestConfiguration('data',apphome=self.datadir)source=config.sources()['system']self.assertEqual(source['db-driver'],'sqlite')handler=get_test_db_handler(config)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()repo.shutdown()if__name__=='__main__':unittest_main()