提交 6585c1a2 编写于 作者: P Pablo Hoffman

removed (somewhat hacky) MAIL_DEBUG setting

上级 e189861b
......@@ -58,9 +58,6 @@ uses `Twisted non-blocking IO`_, like the rest of the framework.
Send email to the given recipients. Emits the :signal:`mail_sent` signal.
If :setting:`MAIL_DEBUG` is enabled the :signal:`mail_sent` signal will
be emmited and no actual email will be sent.
:param to: the e-mail recipients
:type to: list
......@@ -136,15 +133,6 @@ Default: ``None``
Password to use for SMTP authentication, along with :setting:`MAIL_USER`.
.. setting:: MAIL_DEBUG
MAIL_DEBUG
----------
Default: ``False``
Whether to enable the debugging mode.
Mail signals
============
......
......@@ -28,12 +28,13 @@ mail_sent = object()
class MailSender(object):
def __init__(self, smtphost=None, mailfrom=None, smtpuser=None, smtppass=None, \
smtpport=None):
smtpport=None, debug=False):
self.smtphost = smtphost or settings['MAIL_HOST']
self.smtpport = smtpport or settings.getint('MAIL_PORT')
self.smtpuser = smtpuser or settings['MAIL_USER']
self.smtppass = smtppass or settings['MAIL_PASS']
self.mailfrom = mailfrom or settings['MAIL_FROM']
self.debug = debug
if not self.smtphost or not self.mailfrom:
raise NotConfigured("MAIL_HOST and MAIL_FROM settings are required")
......@@ -67,7 +68,7 @@ class MailSender(object):
send_catch_log(signal=mail_sent, to=to, subject=subject, body=body,
cc=cc, attach=attachs, msg=msg)
if settings.getbool('MAIL_DEBUG'):
if self.debug:
log.msg('Debug mail sent OK: To=%s Cc=%s Subject="%s" Attachs=%d' % \
(to, cc, subject, len(attachs)), level=log.DEBUG)
return
......
......@@ -3,22 +3,20 @@ import unittest
from scrapy.xlib.pydispatch import dispatcher
from scrapy.conf import settings
from scrapy.mail import MailSender, mail_sent
class MailSenderTest(unittest.TestCase):
def setUp(self):
settings.disabled = False
settings.overrides['MAIL_DEBUG'] = True
self.catched_msg = None
dispatcher.connect(self._catch_mail_sent, signal=mail_sent)
def tearDown(self):
dispatcher.disconnect(self._catch_mail_sent, signal=mail_sent)
def test_send(self):
mailsender = MailSender()
mailsender = MailSender(debug=True)
mailsender.send(to=['test@scrapy.org'], subject='subject', body='body')
assert self.catched_msg
......@@ -38,7 +36,7 @@ class MailSenderTest(unittest.TestCase):
attach.seek(0)
attachs = [('attachment', 'text/plain', attach)]
mailsender = MailSender()
mailsender = MailSender(debug=True)
mailsender.send(to=['test@scrapy.org'], subject='subject', body='body',
attachs=attachs)
......@@ -59,10 +57,6 @@ class MailSenderTest(unittest.TestCase):
self.assertEqual(text.get_payload(decode=True), 'body')
self.assertEqual(attach.get_payload(decode=True), 'content')
def tearDown(self):
del settings.overrides['MAIL_DEBUG']
settings.disabled = True
def _catch_mail_sent(self, **kwargs):
self.catched_msg = dict(**kwargs)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册