Set a default message sender if no sender set in DebugMailer #56

Merged
merged 1 commit into from Dec 10, 2014

Projects

None yet

3 participants

@zupo
Contributor
zupo commented Mar 12, 2014

Use-case: I construct Messages in my code without a sender, because I want to
use the default_sender as the sender. Works as a charm with Mailer.

However, when I use DebugMailer with these Messages, I get a message a
validation error, because the sender is not set. The Mailer class takes
care of setting the sender if default sender is set, but the DebugMailer
does not do that. This patch then sets a dummy sender, if no sender is set in
Message, to allow using DebugMailer with sender-less Messages.

@tseaver
Member
tseaver commented Apr 30, 2014

Thanks for the patch! It needs a test (to ensure we don't regress) in 'pyramid_mailer/tests/test_mailer:DebugMailerTests'.

@zupo
Contributor
zupo commented May 3, 2014

Of course! Added.

@tseaver tseaver and 1 other commented on an outdated diff May 3, 2014
pyramid_mailer/tests/test_mailer.py
@@ -58,6 +59,15 @@ def test__send(self):
files = self._listFiles()
self.assertEqual(len(files), 1)
+ def test_default_sender(self):
+ mailer = self._makeOne()
+ msg = _makeMessage(sender=None)
+ mailer.send_sendmail(msg)
+ files = self._listFiles()
+ self.assertEqual(len(files), 1)
+ msg = open(os.path.join(self._tempdir, files[0]), 'r')
+ self.assertIn('From nobody', msg.read())
@tseaver
tseaver May 3, 2014 Member

Unfortunately, that test would pass even without the default sender: he "Unix From" header will be set regardless of whether the 'sender' is present. You want to be testing for 'From: nobody' instead.

@zupo
zupo May 3, 2014 Contributor

Good catch, tnx! Fixing now ...

@zupo zupo Set a default message sender if no sender set in DebugMailer
Use-case: I construct Messages in my code without a sender, because I want to
use the ``default_sender`` as the sender. Works as a charm with ``Mailer``.

However, when I use ``DebugMailer`` with these Messages, I get a validation
error, because the sender is not set. The ``Mailer`` class takes care of
setting the sender if default sender is set, but the ``DebugMailer`` does not
do that. This patch then sets a dummy sender, if no sender is set in Message,
to allow using ``DebugMailer`` with sender-less Messages.
137161f
@zupo
Contributor
zupo commented May 3, 2014

Good catch, thanks! Fixed!

@tilgovi
tilgovi commented Jun 24, 2014

Looks good to me. I ran into this as well.

@zupo
Contributor
zupo commented Sep 30, 2014

@tseaver: anything else I can do to get this merged?

@tseaver tseaver merged commit 2b7d1bb into Pylons:master Dec 10, 2014
@tseaver
Member
tseaver commented Dec 10, 2014

Thanks!

@tseaver tseaver added a commit that referenced this pull request Dec 10, 2014
@tseaver tseaver Changelog entry for PR #56. 6776c83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment