43 from cubicweb import cwconfig, devtools, web, server |
43 from cubicweb import cwconfig, devtools, web, server |
44 from cubicweb.dbapi import ProgrammingError, DBAPISession, repo_connect |
44 from cubicweb.dbapi import ProgrammingError, DBAPISession, repo_connect |
45 from cubicweb.sobjects import notification |
45 from cubicweb.sobjects import notification |
46 from cubicweb.web import Redirect, application |
46 from cubicweb.web import Redirect, application |
47 from cubicweb.server.session import security_enabled |
47 from cubicweb.server.session import security_enabled |
|
48 from cubicweb.server.hook import SendMailOp |
48 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
49 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS |
49 from cubicweb.devtools import BASE_URL, fake, htmlparser |
50 from cubicweb.devtools import BASE_URL, fake, htmlparser |
50 from cubicweb.utils import json |
51 from cubicweb.utils import json |
51 |
52 |
52 # low-level utilities ########################################################## |
53 # low-level utilities ########################################################## |
289 server.set_debug(debugmode) |
290 server.set_debug(debugmode) |
290 |
291 |
291 # default test setup and teardown ######################################### |
292 # default test setup and teardown ######################################### |
292 |
293 |
293 def setUp(self): |
294 def setUp(self): |
|
295 # monkey patch send mail operation so emails are sent synchronously |
|
296 self._old_mail_commit_event = SendMailOp.commit_event |
|
297 SendMailOp.commit_event = SendMailOp.sendmails |
294 pause_tracing() |
298 pause_tracing() |
295 previous_failure = self.__class__.__dict__.get('_repo_init_failed') |
299 previous_failure = self.__class__.__dict__.get('_repo_init_failed') |
296 if previous_failure is not None: |
300 if previous_failure is not None: |
297 self.skipTest('repository is not initialised: %r' % previous_failure) |
301 self.skipTest('repository is not initialised: %r' % previous_failure) |
298 try: |
302 try: |
310 if not self.cnx._closed: |
314 if not self.cnx._closed: |
311 self.cnx.rollback() |
315 self.cnx.rollback() |
312 for cnx in self._cnxs: |
316 for cnx in self._cnxs: |
313 if not cnx._closed: |
317 if not cnx._closed: |
314 cnx.close() |
318 cnx.close() |
|
319 SendMailOp.commit_event = self._old_mail_commit_event |
315 |
320 |
316 def setup_database(self): |
321 def setup_database(self): |
317 """add your database setup code by overriding this method""" |
322 """add your database setup code by overriding this method""" |
318 |
323 |
319 # user / session management ############################################### |
324 # user / session management ############################################### |