devtools/testlib.py
changeset 5177 395e1ff018ae
parent 5174 78438ad513ca
parent 5175 6efb7a7ae570
child 5223 6abd6e3599f4
equal deleted inserted replaced
5176:ddd5219d7eef 5177:395e1ff018ae
   263             raise
   263             raise
   264         resume_tracing()
   264         resume_tracing()
   265         self.setup_database()
   265         self.setup_database()
   266         self.commit()
   266         self.commit()
   267         MAILBOX[:] = [] # reset mailbox
   267         MAILBOX[:] = [] # reset mailbox
       
   268         self._cnxs = []
       
   269 
       
   270     def tearDown(self):
       
   271         for cnx in self._cnxs:
       
   272             if not cnx._closed:
       
   273                 cnx.close()
   268 
   274 
   269     def setup_database(self):
   275     def setup_database(self):
   270         """add your database setup code by overriding this method"""
   276         """add your database setup code by overriding this method"""
   271 
   277 
   272     # user / session management ###############################################
   278     # user / session management ###############################################
   304             if not kwargs:
   310             if not kwargs:
   305                 kwargs['password'] = str(login)
   311                 kwargs['password'] = str(login)
   306             self.cnx = repo_connect(self.repo, unicode(login),
   312             self.cnx = repo_connect(self.repo, unicode(login),
   307                                     cnxprops=ConnectionProperties('inmemory'),
   313                                     cnxprops=ConnectionProperties('inmemory'),
   308                                     **kwargs)
   314                                     **kwargs)
       
   315             self._cnxs.append(self.cnx)
   309         if login == self.vreg.config.anonymous_user()[0]:
   316         if login == self.vreg.config.anonymous_user()[0]:
   310             self.cnx.anonymous_connection = True
   317             self.cnx.anonymous_connection = True
   311         return self.cnx
   318         return self.cnx
   312 
   319 
   313     def restore_connection(self):
   320     def restore_connection(self):
   314         if not self.cnx is self._orig_cnx:
   321         if not self.cnx is self._orig_cnx:
   315             try:
   322             try:
   316                 self.cnx.close()
   323                 self.cnx.close()
       
   324                 self._cnxs.remove(self.cnx)
   317             except ProgrammingError:
   325             except ProgrammingError:
   318                 pass # already closed
   326                 pass # already closed
   319         self.cnx = self._orig_cnx
   327         self.cnx = self._orig_cnx
   320 
   328 
   321     # db api ##################################################################
   329     # db api ##################################################################