-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: type validation on to_emails parameter on mail object (#920)
- Loading branch information
Showing
2 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,6 +284,95 @@ def test_multiple_emails_to_multiple_recipients(self): | |
}''') | ||
) | ||
|
||
def test_value_error_is_raised_on_to_emails_set_to_list_of_lists(self): | ||
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) | ||
self.maxDiff = None | ||
to_emails = [ | ||
['[email protected]', 'Example To Name 0'], | ||
['[email protected]', 'Example To Name 1'] | ||
] | ||
|
||
with self.assertRaises(ValueError): | ||
Mail( | ||
from_email=From('[email protected]', 'Example From Name'), | ||
to_emails=to_emails, | ||
subject=Subject('Sending with SendGrid is Fun'), | ||
plain_text_content=PlainTextContent( | ||
'and easy to do anywhere, even with Python'), | ||
html_content=HtmlContent( | ||
'<strong>and easy to do anywhere, even with Python</strong>')) | ||
|
||
def test_error_is_not_raised_on_to_emails_set_to_list_of_tuples(self): | ||
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) | ||
self.maxDiff = None | ||
to_emails = [ | ||
('[email protected]', 'Example To Name 0'), | ||
('[email protected]', 'Example To Name 1') | ||
] | ||
|
||
try: | ||
Mail( | ||
from_email=From('[email protected]', 'Example From Name'), | ||
to_emails=to_emails, | ||
subject=Subject('Sending with SendGrid is Fun'), | ||
plain_text_content=PlainTextContent( | ||
'and easy to do anywhere, even with Python'), | ||
html_content=HtmlContent( | ||
'<strong>and easy to do anywhere, even with Python</strong>')) | ||
except: | ||
self.fail('Mail() raised an error on list of tuples') | ||
|
||
def test_error_is_not_raised_on_to_emails_set_to_list_of_strs(self): | ||
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) | ||
self.maxDiff = None | ||
to_emails = ['[email protected]', '[email protected]'] | ||
|
||
try: | ||
Mail( | ||
from_email=From('[email protected]', 'Example From Name'), | ||
to_emails=to_emails, | ||
subject=Subject('Sending with SendGrid is Fun'), | ||
plain_text_content=PlainTextContent( | ||
'and easy to do anywhere, even with Python'), | ||
html_content=HtmlContent( | ||
'<strong>and easy to do anywhere, even with Python</strong>')) | ||
except: | ||
self.fail('Mail() raised an error on list of strings') | ||
|
||
def test_error_is_not_raised_on_to_emails_set_to_a_str(self): | ||
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) | ||
self.maxDiff = None | ||
to_emails = '[email protected]' | ||
|
||
try: | ||
Mail( | ||
from_email=From('[email protected]', 'Example From Name'), | ||
to_emails=to_emails, | ||
subject=Subject('Sending with SendGrid is Fun'), | ||
plain_text_content=PlainTextContent( | ||
'and easy to do anywhere, even with Python'), | ||
html_content=HtmlContent( | ||
'<strong>and easy to do anywhere, even with Python</strong>')) | ||
except: | ||
self.fail('Mail() raised an error on a string') | ||
|
||
def test_error_is_not_raised_on_to_emails_set_to_a_tuple(self): | ||
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) | ||
self.maxDiff = None | ||
to_emails = ('[email protected]', 'Example To Name 0') | ||
|
||
try: | ||
Mail( | ||
from_email=From('[email protected]', 'Example From Name'), | ||
to_emails=to_emails, | ||
subject=Subject('Sending with SendGrid is Fun'), | ||
plain_text_content=PlainTextContent( | ||
'and easy to do anywhere, even with Python'), | ||
html_content=HtmlContent( | ||
'<strong>and easy to do anywhere, even with Python</strong>')) | ||
except: | ||
self.fail('Mail() raised an error on a tuple of strings') | ||
|
||
def test_dynamic_template_data(self): | ||
self.maxDiff = None | ||
|
||
|