[test] silence warnings for unittest_schema by upgrading to new 3.19 API
# 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/>.fromcubicweb.devtools.testlibimportCubicWebTCfromcubicweb.server.sessionimportHOOKS_ALLOW_ALL,HOOKS_DENY_ALL,ConnectionclassInternalSessionTC(CubicWebTC):deftest_dbapi_query(self):session=self.repo.internal_session()self.assertFalse(session.running_dbapi_query)session.close()deftest_integrity_hooks(self):withself.repo.internal_session()assession:self.assertEqual(HOOKS_ALLOW_ALL,session.hooks_mode)self.assertEqual(set(('integrity','security')),session.disabled_hook_categories)self.assertEqual(set(),session.enabled_hook_categories)session.commit()self.assertEqual(HOOKS_ALLOW_ALL,session.hooks_mode)self.assertEqual(set(('integrity','security')),session.disabled_hook_categories)self.assertEqual(set(),session.enabled_hook_categories)classSessionTC(CubicWebTC):deftest_hooks_control(self):session=self.session# this test check the "old" behavior of session with automatic connection management# close the default cnx, we do nto want it to interfer with the testself.cnx.close()# open a dedicated onesession.set_cnx('Some-random-cnx-unrelated-to-the-default-one')# go test goself.assertEqual(HOOKS_ALLOW_ALL,session.hooks_mode)self.assertEqual(set(),session.disabled_hook_categories)self.assertEqual(set(),session.enabled_hook_categories)self.assertEqual(1,len(session._cnxs))withsession.deny_all_hooks_but('metadata'):self.assertEqual(HOOKS_DENY_ALL,session.hooks_mode)self.assertEqual(set(),session.disabled_hook_categories)self.assertEqual(set(('metadata',)),session.enabled_hook_categories)session.commit()self.assertEqual(HOOKS_DENY_ALL,session.hooks_mode)self.assertEqual(set(),session.disabled_hook_categories)self.assertEqual(set(('metadata',)),session.enabled_hook_categories)session.rollback()self.assertEqual(HOOKS_DENY_ALL,session.hooks_mode)self.assertEqual(set(),session.disabled_hook_categories)self.assertEqual(set(('metadata',)),session.enabled_hook_categories)withsession.allow_all_hooks_but('integrity'):self.assertEqual(HOOKS_ALLOW_ALL,session.hooks_mode)self.assertEqual(set(('integrity',)),session.disabled_hook_categories)self.assertEqual(set(('metadata',)),session.enabled_hook_categories)# not changed in such caseself.assertEqual(HOOKS_DENY_ALL,session.hooks_mode)self.assertEqual(set(),session.disabled_hook_categories)self.assertEqual(set(('metadata',)),session.enabled_hook_categories)# leaving context manager with no transaction running should reset the# transaction local storage (and associated cnxset)self.assertEqual({},session._cnxs)self.assertEqual(None,session.cnxset)self.assertEqual(HOOKS_ALLOW_ALL,session.hooks_mode,session.HOOKS_ALLOW_ALL)self.assertEqual(set(),session.disabled_hook_categories)self.assertEqual(set(),session.enabled_hook_categories)deftest_explicite_connection(self):withself.session.new_cnx()ascnx:rset=cnx.execute('Any X LIMIT 1 WHERE X is CWUser')self.assertEqual(1,len(rset))user=rset.get_entity(0,0)user.cw_delete()cnx.rollback()new_user=cnx.entity_from_eid(user.eid)self.assertIsNotNone(new_user.login)self.assertFalse(cnx._open)deftest_internal_cnx(self):withself.repo.internal_cnx()ascnx:rset=cnx.execute('Any X LIMIT 1 WHERE X is CWUser')self.assertEqual(1,len(rset))user=rset.get_entity(0,0)user.cw_delete()cnx.rollback()new_user=cnx.entity_from_eid(user.eid)self.assertIsNotNone(new_user.login)self.assertFalse(cnx._open)if__name__=='__main__':fromlogilab.common.testlibimportunittest_mainunittest_main()