Skip to content

Commit

Permalink
Restore cc/bcc only support and add test from Chris:
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatterson committed Mar 20, 2012
1 parent 3586e74 commit fb2a013
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 0 additions & 4 deletions pyramid_mailer/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ def validate(self):
if not (self.recipients or self.cc or self.bcc):
raise InvalidMessage("No recipients have been added")

if (self.cc or self.bcc) and not self.recipients:
raise InvalidMessage("Must have at least one direct recipient "
"even if cc or bcc set")

if not self.body and not self.html:
raise InvalidMessage("No body has been set")

Expand Down
25 changes: 21 additions & 4 deletions pyramid_mailer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,22 @@ def test_cc_without_recipients(self):
body="testing",
cc=["tosomeoneelse@example.com"])
mailer = Mailer()
from pyramid_mailer.exceptions import InvalidMessage
self.assertRaises(InvalidMessage, mailer.send, msg)
msgid = mailer.send(msg)
response = msg.get_response()

self.assertTrue("Cc: tosomeoneelse@example.com" in str(response))
self.assertTrue(msgid)

def test_cc_without_recipients_2(self):

from pyramid_mailer.message import Message

msg = Message(subject="testing",
sender="sender@example.com",
body="testing",
cc=["tosomeoneelse@example.com"])
response = msg.get_response()
self.assertTrue("Cc: tosomeoneelse@example.com" in str(response))

def test_bcc_without_recipients(self):

Expand All @@ -181,8 +195,11 @@ def test_bcc_without_recipients(self):
body="testing",
bcc=["tosomeoneelse@example.com"])
mailer = Mailer()
from pyramid_mailer.exceptions import InvalidMessage
self.assertRaises(InvalidMessage, mailer.send, msg)
msgid = mailer.send(msg)
response = msg.get_response()

self.assertFalse("Bcc: tosomeoneelse@example.com" in str(response))
self.assertTrue(msgid)

def test_attach(self):

Expand Down

0 comments on commit fb2a013

Please sign in to comment.