cubicweb/devtools/testlib.py
changeset 11348 70337ad23145
parent 11270 a9dc97b87ced
child 11462 2046b3a4da5d
equal deleted inserted replaced
11347:b4dcfd734686 11348:70337ad23145
    67 
    67 
    68 class BaseTestCase(TestCase):
    68 class BaseTestCase(TestCase):
    69 
    69 
    70     @classproperty
    70     @classproperty
    71     @cached
    71     @cached
    72     def datadir(cls): # pylint: disable=E0213
    72     def datadir(cls):  # pylint: disable=E0213
    73         """helper attribute holding the standard test's data directory
    73         """helper attribute holding the standard test's data directory
    74         """
    74         """
    75         mod = sys.modules[cls.__module__]
    75         mod = sys.modules[cls.__module__]
    76         return join(dirname(abspath(mod.__file__)), 'data')
    76         return join(dirname(abspath(mod.__file__)), 'data')
    77     # cache it (use a class method to cache on class since TestCase is
    77     # cache it (use a class method to cache on class since TestCase is
   887         # not properly cleaned between tests
   887         # not properly cleaned between tests
   888         self.open_sessions = sh.session_manager._sessions = {}
   888         self.open_sessions = sh.session_manager._sessions = {}
   889         return req, self.session
   889         return req, self.session
   890 
   890 
   891     def assertAuthSuccess(self, req, origsession, nbsessions=1):
   891     def assertAuthSuccess(self, req, origsession, nbsessions=1):
   892         sh = self.app.session_handler
       
   893         session = self.app.get_session(req)
   892         session = self.app.get_session(req)
   894         cnx = repoapi.Connection(session)
   893         cnx = repoapi.Connection(session)
   895         req.set_cnx(cnx)
   894         req.set_cnx(cnx)
   896         self.assertEqual(len(self.open_sessions), nbsessions, self.open_sessions)
   895         self.assertEqual(len(self.open_sessions), nbsessions, self.open_sessions)
   897         self.assertEqual(session.login, origsession.login)
   896         self.assertEqual(session.login, origsession.login)
   925         'text/plain': None,
   924         'text/plain': None,
   926         'text/comma-separated-values': None,
   925         'text/comma-separated-values': None,
   927         'text/x-vcard': None,
   926         'text/x-vcard': None,
   928         'text/calendar': None,
   927         'text/calendar': None,
   929         'image/png': None,
   928         'image/png': None,
   930         }
   929     }
   931     # maps vid : validator name (override content_type_validators)
   930     # maps vid : validator name (override content_type_validators)
   932     vid_validators = dict((vid, htmlparser.VALMAP[valkey])
   931     vid_validators = dict((vid, htmlparser.VALMAP[valkey])
   933                           for vid, valkey in VIEW_VALIDATORS.items())
   932                           for vid, valkey in VIEW_VALIDATORS.items())
   934 
   933 
   935     def view(self, vid, rset=None, req=None, template='main-template',
   934     def view(self, vid, rset=None, req=None, template='main-template',
  1053                     line_template = " %" + ("%i" % width) + "i: %s"
  1052                     line_template = " %" + ("%i" % width) + "i: %s"
  1054                     # XXX no need to iterate the whole file except to get
  1053                     # XXX no need to iterate the whole file except to get
  1055                     # the line number
  1054                     # the line number
  1056                     content = u'\n'.join(line_template % (idx + 1, line)
  1055                     content = u'\n'.join(line_template % (idx + 1, line)
  1057                                          for idx, line in enumerate(content)
  1056                                          for idx, line in enumerate(content)
  1058                                          if line_context_filter(idx+1, position))
  1057                                          if line_context_filter(idx + 1, position))
  1059                     msg += u'\nfor content:\n%s' % content
  1058                     msg += u'\nfor content:\n%s' % content
  1060             exc = AssertionError(msg)
  1059             exc = AssertionError(msg)
  1061             exc.__traceback__ = tcbk
  1060             exc.__traceback__ = tcbk
  1062             raise exc
  1061             raise exc
  1063 
  1062