@@ -284,6 +284,95 @@ def test_multiple_emails_to_multiple_recipients(self):
284284 }''' )
285285 )
286286
287+ def test_value_error_is_raised_on_to_emails_set_to_list_of_lists (self ):
288+ from sendgrid .helpers .mail import (PlainTextContent , HtmlContent )
289+ self .maxDiff = None
290+ to_emails = [
291+ ['test+to0@example.com' , 'Example To Name 0' ],
292+ ['test+to1@example.com' , 'Example To Name 1' ]
293+ ]
294+
295+ with self .assertRaises (ValueError ):
296+ Mail (
297+ from_email = From ('test+from@example.com' , 'Example From Name' ),
298+ to_emails = to_emails ,
299+ subject = Subject ('Sending with SendGrid is Fun' ),
300+ plain_text_content = PlainTextContent (
301+ 'and easy to do anywhere, even with Python' ),
302+ html_content = HtmlContent (
303+ '<strong>and easy to do anywhere, even with Python</strong>' ))
304+
305+ def test_error_is_not_raised_on_to_emails_set_to_list_of_tuples (self ):
306+ from sendgrid .helpers .mail import (PlainTextContent , HtmlContent )
307+ self .maxDiff = None
308+ to_emails = [
309+ ('test+to0@example.com' , 'Example To Name 0' ),
310+ ('test+to1@example.com' , 'Example To Name 1' )
311+ ]
312+
313+ try :
314+ Mail (
315+ from_email = From ('test+from@example.com' , 'Example From Name' ),
316+ to_emails = to_emails ,
317+ subject = Subject ('Sending with SendGrid is Fun' ),
318+ plain_text_content = PlainTextContent (
319+ 'and easy to do anywhere, even with Python' ),
320+ html_content = HtmlContent (
321+ '<strong>and easy to do anywhere, even with Python</strong>' ))
322+ except :
323+ self .fail ('Mail() raised an error on list of tuples' )
324+
325+ def test_error_is_not_raised_on_to_emails_set_to_list_of_strs (self ):
326+ from sendgrid .helpers .mail import (PlainTextContent , HtmlContent )
327+ self .maxDiff = None
328+ to_emails = ['test+to0@example.com' , 'test+to1@example.com' ]
329+
330+ try :
331+ Mail (
332+ from_email = From ('test+from@example.com' , 'Example From Name' ),
333+ to_emails = to_emails ,
334+ subject = Subject ('Sending with SendGrid is Fun' ),
335+ plain_text_content = PlainTextContent (
336+ 'and easy to do anywhere, even with Python' ),
337+ html_content = HtmlContent (
338+ '<strong>and easy to do anywhere, even with Python</strong>' ))
339+ except :
340+ self .fail ('Mail() raised an error on list of strings' )
341+
342+ def test_error_is_not_raised_on_to_emails_set_to_a_str (self ):
343+ from sendgrid .helpers .mail import (PlainTextContent , HtmlContent )
344+ self .maxDiff = None
345+ to_emails = 'test+to0@example.com'
346+
347+ try :
348+ Mail (
349+ from_email = From ('test+from@example.com' , 'Example From Name' ),
350+ to_emails = to_emails ,
351+ subject = Subject ('Sending with SendGrid is Fun' ),
352+ plain_text_content = PlainTextContent (
353+ 'and easy to do anywhere, even with Python' ),
354+ html_content = HtmlContent (
355+ '<strong>and easy to do anywhere, even with Python</strong>' ))
356+ except :
357+ self .fail ('Mail() raised an error on a string' )
358+
359+ def test_error_is_not_raised_on_to_emails_set_to_a_tuple (self ):
360+ from sendgrid .helpers .mail import (PlainTextContent , HtmlContent )
361+ self .maxDiff = None
362+ to_emails = ('test+to0@example.com' , 'Example To Name 0' )
363+
364+ try :
365+ Mail (
366+ from_email = From ('test+from@example.com' , 'Example From Name' ),
367+ to_emails = to_emails ,
368+ subject = Subject ('Sending with SendGrid is Fun' ),
369+ plain_text_content = PlainTextContent (
370+ 'and easy to do anywhere, even with Python' ),
371+ html_content = HtmlContent (
372+ '<strong>and easy to do anywhere, even with Python</strong>' ))
373+ except :
374+ self .fail ('Mail() raised an error on a tuple of strings' )
375+
287376 def test_dynamic_template_data (self ):
288377 self .maxDiff = None
289378
0 commit comments