[MERGE] prevent sending emails in test mode

bzr revid: rco@openerp.com-20111201160517-1gk7sita6c5uernx
This commit is contained in:
Raphael Collet
2011-12-01 17:05:17 +01:00
2 changed files with 9 additions and 0 deletions
+6
View File
@@ -28,6 +28,7 @@ from email import Encoders
import logging
import re
import smtplib
import threading
from osv import osv
from osv import fields
@@ -381,6 +382,11 @@ class ir_mail_server(osv.osv):
smtp_to_list = filter(None, tools.flatten(map(extract_rfc2822_addresses,[email_to, email_cc, email_bcc])))
assert smtp_to_list, "At least one valid recipient address should be specified for outgoing emails (To/Cc/Bcc)"
# Do not actually send emails in testing mode!
if getattr(threading.currentThread(), 'testing', False):
_logger.log(logging.TEST, "skip sending email in test mode")
return message['Message-Id']
# Get SMTP Server Details from Mail Server
mail_server = None
if mail_server_id:
+3
View File
@@ -31,6 +31,7 @@ import logging
import os
import re
import sys
import threading
import zipfile
import zipimport
@@ -97,11 +98,13 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
cr.commit()
if not tools.config.options['test_disable']:
try:
threading.currentThread().testing = True
_load_data(cr, module_name, idref, mode, 'test')
except Exception, e:
logging.getLogger('init.test').exception(
'Tests failed to execute in module %s', module_name)
finally:
threading.currentThread().testing = False
if tools.config.options['test_commit']:
cr.commit()
else: