[ms] fix error in synchronisation: local_eid return a 2-uple
# copyright 2003-2010 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/>."""this module contains base classes for windmill integration:todo: * import CubicWeb session object into windmill scope to be able to run RQL * manage command line option from pytest to run specific use tests only"""importos,os.pathasospfromloggingimportgetLogger,ERRORimportsys# imported by default to simplify further import statementsfromlogilab.common.testlibimportTestCase,unittest_mainimportwindmillfromwindmill.depimportfunctestfromwindmill.bin.admin_libimportconfigure_global_settings,setup,teardownfromcubicweb.devtools.httptestimportCubicWebServerTC,CubicWebServerConfig# Excerpt from :ref:`windmill.authoring.unit`classUnitTestReporter(functest.reports.FunctestReportInterface):defsummary(self,test_list,totals_dict,stdout_capture):self.test_list=test_listunittestreporter=UnitTestReporter()functest.reports.register_reporter(unittestreporter)classCubicWebWindmillUseCase(CubicWebServerTC):"""basic class for Windmill use case tests If you want to change cubicweb test server parameters, define a new :class:`CubicWebServerConfig` and override the :var:`configcls` attribute: configcls = CubicWebServerConfig From Windmill configuration: .. attribute:: browser identification string (firefox|ie|safari|chrome) (firefox by default) .. attribute :: edit_test load and edit test for debugging (False by default) .. attribute:: test_dir (optional) testing file path or directory (windmill directory under your unit case file by default) Examples: browser = 'firefox' test_dir = osp.join(__file__, 'windmill') edit_test = False If you prefer, you can put here the use cases recorded by windmill GUI (services transformer) instead of the windmill sub-directory You can change `test_dir` as following: test_dir = __file__ Instead of toggle `edit_test` value, try `pytest -i` """browser='firefox'edit_test="-i"insys.argv# detection for pytest invocation# Windmill use case are written with no anonymous useranonymous_logged=Falsedef_test_dir(self):"""access to class attribute if possible or make assumption of expected directory"""try:returngetattr(self,'test_dir')exceptAttributeError:ifos.path.basename(sys.argv[0])=="pytest":test_dir=os.getcwd()else:importinspecttest_dir=os.path.dirname(inspect.stack()[-1][1])returnosp.join(test_dir,'windmill')defsetUp(self):# Start CubicWeb session before running the server to populate self.vregCubicWebServerTC.setUp(self)# XXX reduce log output (should be done in a cleaner way)# windmill fu** up our logging configurationforlogkeyin('windmill','logilab','cubicweb'):getLogger(logkey).setLevel(ERROR)self.test_dir=self._test_dir()msg="provide a valid 'test_dir' as the given test file/dir (current: %s)"assertos.path.exists(self.test_dir),(msg%self.test_dir)# windmill setupwindmill.stdout,windmill.stdin=sys.stdout,sys.stdinconfigure_global_settings()windmill.settings['TEST_URL']=self.config['base-url']ifhasattr(self,"windmill_settings"):for(setting,value)inself.windmill_settings.iteritems():windmill.settings[setting]=valueself.windmill_shell_objects=setup()deftearDown(self):teardown(self.windmill_shell_objects)CubicWebServerTC.tearDown(self)deftestWindmill(self):ifself.edit_test:# see windmill.bin.admin_options.Firebugwindmill.settings['INSTALL_FIREBUG']='firebug'windmill.settings.setdefault('MOZILLA_PLUGINS',[]).extend(['/usr/share/mozilla-extensions/','/usr/share/xul-ext/'])controller=self.windmill_shell_objects['start_'+self.browser]()self.windmill_shell_objects['do_test'](self.test_dir,load=self.edit_test,threaded=False)# set a breakpoint to be able to debug windmill testifself.edit_test:importpdb;pdb.set_trace()return# reporterfortestinunittestreporter.test_list:msg=""self._testMethodDoc=getattr(test,"__doc__",None)self._testMethodName=test.__name__# try to display a better message in case of failureifhasattr(test,"tb"):msg='\n'.join(test.tb)self.assertEqual(test.result,True,msg=msg)