devtools/testlib.py
branchtls-sprint
changeset 823 cb8ccbef8fa5
parent 563 a690996639ca
child 829 ea092805d8f8
equal deleted inserted replaced
822:e3d8db01f3f5 823:cb8ccbef8fa5
   156             cu.execute(rql, args)
   156             cu.execute(rql, args)
   157         self.post_populate(cu)
   157         self.post_populate(cu)
   158         self.commit()
   158         self.commit()
   159 
   159 
   160     @nocoverage
   160     @nocoverage
   161     def _check_html(self, output, view, template='main'):
   161     def _check_html(self, output, view, template='main-template'):
   162         """raises an exception if the HTML is invalid"""
   162         """raises an exception if the HTML is invalid"""
   163         try:
   163         try:
   164             validatorclass = self.vid_validators[view.id]
   164             validatorclass = self.vid_validators[view.id]
   165         except KeyError:
   165         except KeyError:
   166             if template is None:
   166             if template is None:
   173             return None
   173             return None
   174         validator = validatorclass()
   174         validator = validatorclass()
   175         return validator.parse_string(output.strip())
   175         return validator.parse_string(output.strip())
   176 
   176 
   177 
   177 
   178     def view(self, vid, rset, req=None, template='main', **kwargs):
   178     def view(self, vid, rset, req=None, template='main-template', **kwargs):
   179         """This method tests the view `vid` on `rset` using `template`
   179         """This method tests the view `vid` on `rset` using `template`
   180 
   180 
   181         If no error occured while rendering the view, the HTML is analyzed
   181         If no error occured while rendering the view, the HTML is analyzed
   182         and parsed.
   182         and parsed.
   183 
   183 
   198         else:
   198         else:
   199             self.set_description("testing %s, mod=%s (no rset)" % (vid, view.__module__))
   199             self.set_description("testing %s, mod=%s (no rset)" % (vid, view.__module__))
   200         viewfunc = lambda **k: self.vreg.main_template(req, template, **kwargs)
   200         viewfunc = lambda **k: self.vreg.main_template(req, template, **kwargs)
   201         if template is None: # raw view testing, no template
   201         if template is None: # raw view testing, no template
   202             viewfunc = view.dispatch
   202             viewfunc = view.dispatch
   203         elif template == 'main':
   203         elif template == 'main-template':
   204             _select_view_and_rset = TheMainTemplate._select_view_and_rset
   204             _select_view_and_rset = TheMainTemplate._select_view_and_rset
   205             # patch TheMainTemplate.process_rql to avoid recomputing resultset
   205             # patch TheMainTemplate.process_rql to avoid recomputing resultset
   206             def __select_view_and_rset(self, view=view, rset=rset):
   206             def __select_view_and_rset(self, view=view, rset=rset):
   207                 self.rset = rset
   207                 self.rset = rset
   208                 return view, rset
   208                 return view, rset
   209             TheMainTemplate._select_view_and_rset = __select_view_and_rset
   209             TheMainTemplate._select_view_and_rset = __select_view_and_rset
   210         try:
   210         try:
   211             return self._test_view(viewfunc, view, template, **kwargs)
   211             return self._test_view(viewfunc, view, template, **kwargs)
   212         finally:
   212         finally:
   213             if template == 'main':
   213             if template == 'main-template':
   214                 TheMainTemplate._select_view_and_rset = _select_view_and_rset
   214                 TheMainTemplate._select_view_and_rset = _select_view_and_rset
   215 
   215 
   216 
   216 
   217     def _test_view(self, viewfunc, view, template='main', **kwargs):
   217     def _test_view(self, viewfunc, view, template='main-template', **kwargs):
   218         """this method does the actual call to the view
   218         """this method does the actual call to the view
   219 
   219 
   220         If no error occured while rendering the view, the HTML is analyzed
   220         If no error occured while rendering the view, the HTML is analyzed
   221         and parsed.
   221         and parsed.
   222 
   222 
   330                 propdefs[k]['default'] = True
   330                 propdefs[k]['default'] = True
   331         for view in self.list_views_for(rset):
   331         for view in self.list_views_for(rset):
   332             backup_rset = rset._prepare_copy(rset.rows, rset.description)
   332             backup_rset = rset._prepare_copy(rset.rows, rset.description)
   333             yield InnerTest(self._testname(rset, view.id, 'view'),
   333             yield InnerTest(self._testname(rset, view.id, 'view'),
   334                             self.view, view.id, rset,
   334                             self.view, view.id, rset,
   335                             rset.req.reset_headers(), 'main')
   335                             rset.req.reset_headers(), 'main-template')
   336             # We have to do this because some views modify the
   336             # We have to do this because some views modify the
   337             # resultset's syntax tree
   337             # resultset's syntax tree
   338             rset = backup_rset
   338             rset = backup_rset
   339         for action in self.list_actions_for(rset):
   339         for action in self.list_actions_for(rset):
   340             # XXX this seems a bit dummy
   340             # XXX this seems a bit dummy