def test_send_mail(self, throws_exception, workflow): smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', } rcm = {'version': 1, 'smtp': smtp_map, 'openshift': {'url': 'https://something.com'}} workflow.conf = Configuration(raw_config=rcm) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com') class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) sendmail_chain = (flexmock(smtp_inst).should_receive('sendmail'). with_args('*****@*****.**', ['*****@*****.**'], str)) if throws_exception: sendmail_chain.and_raise(smtplib.SMTPException, "foo") flexmock(smtp_inst).should_receive('quit') if throws_exception: with pytest.raises(SMTPException) as e: p._send_mail(['*****@*****.**'], 'subject', 'body') assert str(e.value) == 'foo' else: p._send_mail(['*****@*****.**'], 'subject', 'body')
def test_send_mail(self, throws_exception): class WF(object): exit_results = {} p = SendMailPlugin(None, WF(), from_address='*****@*****.**', smtp_host='smtp.spam.com') class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) sendmail_chain = ( flexmock(smtp_inst).should_receive('sendmail').with_args( '*****@*****.**', ['*****@*****.**'], str)) if throws_exception: sendmail_chain.and_raise(smtplib.SMTPException, "foo") flexmock(smtp_inst).should_receive('quit') if throws_exception: with pytest.raises(SMTPException) as e: p._send_mail(['*****@*****.**'], 'subject', 'body') assert str(e.value) == 'foo' else: p._send_mail(['*****@*****.**'], 'subject', 'body')
def test_send_mail(self): p = SendMailPlugin(None, None, from_address='*****@*****.**', smtp_uri='smtp.spam.com') class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) flexmock(smtp_inst).should_receive('sendmail').\ with_args('*****@*****.**', ['*****@*****.**'], str) flexmock(smtp_inst).should_receive('quit') p._send_mail(['*****@*****.**'], 'subject', 'body')
def test_send_mail(self): p = SendMailPlugin(None, None, from_address='*****@*****.**', smtp_url='smtp.spam.com') class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) flexmock(smtp_inst).should_receive('sendmail').\ with_args('*****@*****.**', ['*****@*****.**'], str) flexmock(smtp_inst).should_receive('quit') p._send_mail(['*****@*****.**'], 'subject', 'body')
def test_send_mail(self, throws_exception, reactor_config_map): class WF(object): exit_results = {} plugin_workspace = {} workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', } workflow.plugin_workspace[ReactorConfigPlugin.key] = {} workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig({'version': 1, 'smtp': smtp_map}) p = SendMailPlugin(None, workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com') class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) sendmail_chain = ( flexmock(smtp_inst).should_receive('sendmail').with_args( '*****@*****.**', ['*****@*****.**'], str)) if throws_exception: sendmail_chain.and_raise(smtplib.SMTPException, "foo") flexmock(smtp_inst).should_receive('quit') if throws_exception: with pytest.raises(SMTPException) as e: p._send_mail(['*****@*****.**'], 'subject', 'body') assert str(e.value) == 'foo' else: p._send_mail(['*****@*****.**'], 'subject', 'body')
def test_send_mail(self, throws_exception, reactor_config_map): class WF(object): exit_results = {} plugin_workspace = {} workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', } workflow.plugin_workspace[ReactorConfigPlugin.key] = {} workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig({'version': 1, 'smtp': smtp_map}) p = SendMailPlugin(None, workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com') class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) sendmail_chain = (flexmock(smtp_inst).should_receive('sendmail'). with_args('*****@*****.**', ['*****@*****.**'], str)) if throws_exception: sendmail_chain.and_raise(smtplib.SMTPException, "foo") flexmock(smtp_inst).should_receive('quit') if throws_exception: with pytest.raises(SMTPException) as e: p._send_mail(['*****@*****.**'], 'subject', 'body') assert str(e.value) == 'foo' else: p._send_mail(['*****@*****.**'], 'subject', 'body')