mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-23 13:24:20 +00:00
removed (somewhat hacky) MAIL_DEBUG setting
This commit is contained in:
parent
e189861b46
commit
6585c1a28f
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user