# 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.## 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/>.importreimportsysfromlogilab.common.testlibimportunittest_mainfromcubicwebimportForbiddenfromcubicweb.devtools.testlibimportCubicWebTCfromcubicweb.viewimportStartupViewfromcubicweb.webimportRedirectclassErrorViewTC(CubicWebTC):defsetUp(self):super(ErrorViewTC,self).setUp()self.vreg.config['submit-mail']="test@logilab.fr"self.vreg.config['print-traceback']="yes"deftest_error_generation(self):""" tests """classMyWrongView(StartupView):__regid__='my-view'defcall(self):raiseValueError('This is wrong')withself.temporary_appobjects(MyWrongView):withself.admin_access.web_request()asreq:try:self.view('my-view',req=req)exceptExceptionase:req.data['excinfo']=sys.exc_info()req.data['ex']=ehtml=self.view('error',req=req)self.failUnless(re.search(r'^<input name="__signature" type="hidden" ''value="[0-9a-f]{32}" />$',html.source,re.M))deftest_error_submit_nosig(self):""" tests that the reportbug controller refuses submission if there is not content signature """withself.admin_access.web_request()asreq:req.form={'description':u'toto'}withself.assertRaises(Forbidden)ascm:self.ctrl_publish(req,'reportbug')deftest_error_submit_wrongsig(self):""" tests that the reportbug controller refuses submission if the content signature is invalid """withself.admin_access.web_request()asreq:req.form={'__signature':'X','description':u'toto'}withself.assertRaises(Forbidden)ascm:self.ctrl_publish(req,'reportbug')deftest_error_submit_ok(self):""" tests that the reportbug controller accept the email submission if the content signature is valid """withself.admin_access.web_request()asreq:sign=self.vreg.config.sign_text('toto')req.form={'__signature':sign,'description':u'toto'}withself.assertRaises(Redirect)ascm:self.ctrl_publish(req,'reportbug')if__name__=='__main__':unittest_main()