devtools/testlib.py
branchstable
changeset 5175 6efb7a7ae570
parent 5128 e5d300d75519
child 5177 395e1ff018ae
child 5229 67dbd07a05f3
equal deleted inserted replaced
5172:865a3e522add 5175:6efb7a7ae570
   259             raise
   259             raise
   260         resume_tracing()
   260         resume_tracing()
   261         self.setup_database()
   261         self.setup_database()
   262         self.commit()
   262         self.commit()
   263         MAILBOX[:] = [] # reset mailbox
   263         MAILBOX[:] = [] # reset mailbox
       
   264         self._cnxs = []
       
   265 
       
   266     def tearDown(self):
       
   267         for cnx in self._cnxs:
       
   268             if not cnx._closed:
       
   269                 cnx.close()
   264 
   270 
   265     def setup_database(self):
   271     def setup_database(self):
   266         """add your database setup code by overriding this method"""
   272         """add your database setup code by overriding this method"""
   267 
   273 
   268     # user / session management ###############################################
   274     # user / session management ###############################################
   300             if not kwargs:
   306             if not kwargs:
   301                 kwargs['password'] = str(login)
   307                 kwargs['password'] = str(login)
   302             self.cnx = repo_connect(self.repo, unicode(login),
   308             self.cnx = repo_connect(self.repo, unicode(login),
   303                                     cnxprops=ConnectionProperties('inmemory'),
   309                                     cnxprops=ConnectionProperties('inmemory'),
   304                                     **kwargs)
   310                                     **kwargs)
       
   311             self._cnxs.append(self.cnx)
   305         if login == self.vreg.config.anonymous_user()[0]:
   312         if login == self.vreg.config.anonymous_user()[0]:
   306             self.cnx.anonymous_connection = True
   313             self.cnx.anonymous_connection = True
   307         return self.cnx
   314         return self.cnx
   308 
   315 
   309     def restore_connection(self):
   316     def restore_connection(self):
   310         if not self.cnx is self._orig_cnx:
   317         if not self.cnx is self._orig_cnx:
   311             try:
   318             try:
   312                 self.cnx.close()
   319                 self.cnx.close()
       
   320                 self._cnxs.remove(self.cnx)
   313             except ProgrammingError:
   321             except ProgrammingError:
   314                 pass # already closed
   322                 pass # already closed
   315         self.cnx = self._orig_cnx
   323         self.cnx = self._orig_cnx
   316 
   324 
   317     # db api ##################################################################
   325     # db api ##################################################################