Exemplo n.º 1
0
 def test_send_mail(self):
     with mailtest.Server() as mt:
         kill_hogs.send_mail('root@exacluster',
                             '*****@*****.**',
                             'abcde',
                             port=1025)
         self.assertEqual(len(mt.emails), 1)
Exemplo n.º 2
0
 def test_mass_email(self):
   with mailtest.Server(smtp_port=1025) as s:
     sender = smtplib.SMTP('localhost', 1025)
     c = 1000 # ~0.240s
     for i in range(c):
       sender.sendmail('*****@*****.**', ['*****@*****.**'], 'msg #%i' % i)
     sender.close()
     self.assertEqual(len(s.emails), c)
Exemplo n.º 3
0
 def test_smtp(self):
   with mailtest.Server(smtp_port=1025) as s:
     sender = smtplib.SMTP('localhost', 1025)
     sender.sendmail('*****@*****.**', ['*****@*****.**'], 'hi')
     sender.close()
     self.assertEqual(len(s.emails), 1)
     self.assertEqual(s.emails[0].frm, '*****@*****.**')
     self.assertEqual(s.emails[0].to, ['*****@*****.**'])
     self.assertEqual(s.emails[0].msg, 'hi')
Exemplo n.º 4
0
 def test_request_only(self, mock_run, mock_terminate, mock_process_iter):
     with mailtest.Server() as mt:
         kill_hogs.request_enforcement()
         kill_hogs.main()
         # check that 10 emails have been sent.
         self.assertEqual(len(mt.emails), 10)
         kill_hogs.main()
         # check that no more emails have been sent
         # as enforcement has not been requested.
         self.assertEqual(len(mt.emails), 10)
Exemplo n.º 5
0
 def test_sendgrid(self):
   with mailtest.Server(sendgrid_port=1080) as s:
     sg = sendgrid.SendGridAPIClient(apikey='any', host='http://*****:*****@example.com', 'Author Name')
     mail.subject = 'test email'
     mail.template_id = '12345'
     for i in range(5):
       person = sendgrid.helpers.mail.Personalization()
       person.add_to(sendgrid.helpers.mail.Email('*****@*****.**' % i, 'Recipient #%i' % i))
       #person.add_substitution(Substitution(unsubscribe_path, user.unsubscribe_path()))
       #person.add_custom_arg(CustomArg("user_id", str(user.id)))
       mail.add_personalization(person)
     body = mail.get()
     sg.client.mail.send.post(request_body=body)
     self.assertEqual(len(s.emails), 5)
     self.assertEqual(s.emails[0].frm, '*****@*****.**')
     self.assertEqual(s.emails[0].to, ['*****@*****.**'])
Exemplo n.º 6
0
 def test_main(self, mock_run, mock_terminate, mock_process_iter):
     with mailtest.Server() as mt:
         kill_hogs.main()
         self.assertEqual(len(mt.emails), 10)