devtools/testlib.py
changeset 6366 1806148d6ce8
parent 6333 e3994fcc21c3
parent 6346 1a968e545e4e
child 6370 8c3d6f739fa3
equal deleted inserted replaced
6333:e3994fcc21c3 6366:1806148d6ce8
   345 
   345 
   346     def login(self, login, **kwargs):
   346     def login(self, login, **kwargs):
   347         """return a connection for the given login/password"""
   347         """return a connection for the given login/password"""
   348         if login == self.admlogin:
   348         if login == self.admlogin:
   349             self.restore_connection()
   349             self.restore_connection()
   350         else:
   350             # definitly don't want autoclose when used as a context manager
   351             if not kwargs:
   351             return self.cnx
   352                 kwargs['password'] = str(login)
   352         autoclose = kwargs.pop('autoclose', True)
   353             self.cnx = repo_connect(self.repo, unicode(login), **kwargs)
   353         if not kwargs:
   354             self.websession = DBAPISession(self.cnx)
   354             kwargs['password'] = str(login)
   355             self._cnxs.append(self.cnx)
   355         self.cnx = repo_connect(self.repo, unicode(login), **kwargs)
       
   356         self.websession = DBAPISession(self.cnx)
       
   357         self._cnxs.append(self.cnx)
   356         if login == self.vreg.config.anonymous_user()[0]:
   358         if login == self.vreg.config.anonymous_user()[0]:
   357             self.cnx.anonymous_connection = True
   359             self.cnx.anonymous_connection = True
   358         return TestCaseConnectionProxy(self, self.cnx)
   360         if autoclose:
       
   361             return TestCaseConnectionProxy(self, self.cnx)
       
   362         return self.cnx
   359 
   363 
   360     def restore_connection(self):
   364     def restore_connection(self):
   361         if not self.cnx is self._orig_cnx[0]:
   365         if not self.cnx is self._orig_cnx[0]:
   362             if not self.cnx._closed:
   366             if not self.cnx._closed:
   363                 self.cnx.close()
   367                 self.cnx.close()