<s> """<STR_LIT>""" <EOL> import mock <EOL> from grr . lib import email_alerts <EOL> from grr . lib import flags <EOL> from grr . lib import test_lib <EOL> from grr . lib . rdfvalues import standard as rdf_standard <EOL> class SendEmailTests ( test_lib . GRRBaseTest ) : <EOL> def setUp ( self ) : <EOL> super ( SendEmailTests , self ) . setUp ( ) <EOL> self . mail_stubber . Stop ( ) <EOL> def testSplitEmailsAndAppendEmailDomain ( self ) : <EOL> self . assertEqual ( <EOL> email_alerts . EMAIL_ALERTER . SplitEmailsAndAppendEmailDomain ( "<STR_LIT>" ) , [ ] ) <EOL> def testSendEmail ( self ) : <EOL> self . smtp_patcher = mock . patch ( "<STR_LIT>" ) <EOL> self . mock_smtp = self . smtp_patcher . start ( ) <EOL> try : <EOL> testdomain = "<STR_LIT>" <EOL> with test_lib . ConfigOverrider ( { "<STR_LIT>" : testdomain } ) : <EOL> smtp_conn = self . mock_smtp . return_value <EOL> to_address = "<STR_LIT>" <EOL> from_address = "<STR_LIT>" <EOL> subject = "<STR_LIT:test>" <EOL> message = "<STR_LIT>" <EOL> email_alerts . EMAIL_ALERTER . SendEmail ( <EOL> to_address , from_address , subject , message ) <EOL> c_from , c_to , msg = smtp_conn . sendmail . call_args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( from_address , c_from ) <EOL> self . assertEqual ( [ to_address ] , c_to ) <EOL> self . assertFalse ( "<STR_LIT>" in msg ) <EOL> to_address = rdf_standard . DomainEmailAddress ( "<STR_LIT>" % testdomain ) <EOL> from_address = "<STR_LIT>" <EOL> subject = "<STR_LIT:test>" <EOL> message = "<STR_LIT>" <EOL> email_alerts . EMAIL_ALERTER . SendEmail ( <EOL> to_address , from_address , subject , message ) <EOL> c_from , c_to , msg = smtp_conn . sendmail . call_args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( from_address , c_from ) <EOL> self . assertEqual ( [ to_address ] , c_to ) <EOL> self . assertFalse ( "<STR_LIT>" in msg ) <EOL> to_address = "<STR_LIT>" <EOL> to_address_expected = [ <EOL> x + testdomain for x in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ] <EOL> cc_address = "<STR_LIT>" <EOL> email_alerts . EMAIL_ALERTER . SendEmail ( to_address , from_address , subject , <EOL> message , cc_addresses = cc_address ) <EOL> c_from , c_to , message = smtp_conn . sendmail . call_args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( from_address , c_from ) <EOL> self . assertEqual ( to_address_expected , c_to ) <EOL> self . assertTrue ( "<STR_LIT>" % testdomain in message ) <EOL> to_address = [ rdf_standard . DomainEmailAddress ( "<STR_LIT>" % testdomain ) , <EOL> rdf_standard . DomainEmailAddress ( "<STR_LIT>" % testdomain ) , <EOL> rdf_standard . DomainEmailAddress ( "<STR_LIT>" % testdomain ) ] <EOL> to_address_expected = [ <EOL> x + testdomain for x in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ] <EOL> cc_address = "<STR_LIT>" <EOL> email_alerts . EMAIL_ALERTER . SendEmail ( to_address , from_address , subject , <EOL> message , cc_addresses = cc_address ) <EOL> c_from , c_to , message = smtp_conn . sendmail . call_args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( from_address , c_from ) <EOL> self . assertEqual ( to_address_expected , c_to ) <EOL> self . assertTrue ( "<STR_LIT>" % testdomain in message ) <EOL> to_address = "<STR_LIT>" <EOL> to_address_expected = [ <EOL> x + testdomain for x in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ] <EOL> cc_address = "<STR_LIT>" <EOL> email_msg_id = "<STR_LIT>" <EOL> email_alerts . EMAIL_ALERTER . SendEmail ( <EOL> to_address , from_address , subject , message , <EOL> cc_addresses = cc_address , message_id = email_msg_id ) <EOL> c_from , c_to , message = smtp_conn . sendmail . call_args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( from_address , c_from ) <EOL> self . assertEqual ( to_address_expected , c_to ) <EOL> self . assertTrue ( "<STR_LIT>" % ( testdomain , testdomain ) in <EOL> message ) <EOL> self . assertTrue ( "<STR_LIT>" % email_msg_id ) <EOL> with test_lib . ConfigOverrider ( { "<STR_LIT>" : None } ) : <EOL> to_address = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> rdf_standard . DomainEmailAddress ( "<STR_LIT>" ) ] <EOL> to_address_expected = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> email_alerts . EMAIL_ALERTER . SendEmail ( to_address , from_address , subject , <EOL> message , cc_addresses = cc_address ) <EOL> c_from , c_to , message = smtp_conn . sendmail . call_args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( from_address , c_from ) <EOL> self . assertEqual ( to_address_expected , c_to ) <EOL> self . assertTrue ( "<STR_LIT>" % ( testdomain , testdomain ) in <EOL> message ) <EOL> finally : <EOL> self . smtp_patcher . stop ( ) <EOL> def main ( argv ) : <EOL> test_lib . GrrTestProgram ( argv = argv ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> flags . StartMain ( main ) </s>
