def test_run_does_nothing_if_conditions_not_met( self, reactor_config_map): # noqa class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True exit_results = {} plugin_workspace = {} workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.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', send_on=[MS]) (flexmock(p).should_receive('_should_send').with_args( True, False, False, False).and_return(False)) flexmock(p).should_receive('_get_receivers_list').times(0) flexmock(p).should_receive('_send_mail').times(0) p.run()
def test_run_ok_and_send(self, workflow): workflow.data.plugin_failed = True class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.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') receivers = ['*****@*****.**', '*****@*****.**'] p = SendMailPlugin(workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[]) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) p.run()
def test_run_does_nothing_if_conditions_not_met(self, reactor_config_map): # noqa class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True exit_results = {} plugin_workspace = {} workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.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', send_on=[MS]) (flexmock(p).should_receive('_should_send') .with_args(True, False, False, False).and_return(False)) flexmock(p).should_receive('_get_receivers_list').times(0) flexmock(p).should_receive('_send_mail').times(0) p.run()
def test_run_invalid_receivers(self, caplog, workflow): workflow.data.plugin_failed = True error_addresses = ['*****@*****.**'] mock_store_metadata_results(workflow) smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'error_addresses': ['*****@*****.**'], } 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', send_on=[], error_addresses=error_addresses) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return([]) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) p.run() assert 'no valid addresses in requested addresses. Doing nothing' in caplog.text
def test_run_ok(self, tmpdir, workflow, source_dir): workflow.data.plugin_failed = True receivers = ['*****@*****.**', '*****@*****.**'] dockerfile = source_dir / DOCKERFILE_FILENAME dockerfile.write_text(MOCK_DOCKERFILE, "utf-8") flexmock(workflow, df_path=str(dockerfile)) mock_store_metadata_results(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', send_on=[]) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_send_mail').with_args(receivers, str, str, None) p.run()
def test_run_fails_to_obtain_receivers(self): class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} error_addresses = ['*****@*****.**'] p = SendMailPlugin(None, WF(), from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[AF], error_addresses=error_addresses) (flexmock(p).should_receive('_should_send').with_args( True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_raise( RuntimeError()) flexmock(p).should_receive('_send_mail').with_args( error_addresses, six.text_type, six.text_type) p.run()
def test_skip_plugin(self, caplog, workflow): rcm = {'version': 1, '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) p.run() log_msg = 'no smtp configuration, skipping plugin' assert log_msg in caplog.text
def test_fails_with_unknown_states(self): p = SendMailPlugin(None, None, smtp_host='smtp.bar.com', from_address='*****@*****.**', send_on=['unknown_state', MS]) with pytest.raises(PluginFailedException) as e: p.run() assert str( e.value) == 'Unknown state(s) "unknown_state" for sendmail plugin'
def test_run_does_nothing_if_conditions_not_met(self): class WF(object): build_result = BuildResult(fail_reason="not built") autorebuild_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') p = SendMailPlugin(None, WF(), send_on=[MS]) flexmock(p).should_receive('_should_send').with_args(True, False, False).and_return(False) flexmock(p).should_receive('_get_receivers_list').times(0) flexmock(p).should_receive('_send_mail').times(0) p.run()
def test_run_does_nothing_if_conditions_not_met(self): class WF(object): build_failed = True autorebuild_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') p = SendMailPlugin(None, WF(), send_on=[MS]) flexmock(p).should_receive('_should_send').with_args(True, False, False).and_return(False) flexmock(p).should_receive('_get_receivers_list').times(0) flexmock(p).should_receive('_send_mail').times(0) p.run()
def test_run_ok(self): class WF(object): build_failed = True autorebuild_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') receivers = ['*****@*****.**', '*****@*****.**'] p = SendMailPlugin(None, WF(), send_on=[AF]) flexmock(p).should_receive('_should_send').with_args(True, False, False).and_return(True) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_send_mail').with_args(receivers, six.text_type, six.text_type) p.run()
def test_run_ok(self): class WF(object): build_result = BuildResult(fail_reason="not built") autorebuild_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') receivers = ['*****@*****.**', '*****@*****.**'] p = SendMailPlugin(None, WF(), send_on=[AF]) flexmock(p).should_receive('_should_send').with_args(True, False, False).and_return(True) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_send_mail').with_args(receivers, six.text_type, six.text_type) p.run()
def test_run_fails_to_obtain_receivers(self): class WF(object): build_result = BuildResult(fail_reason="not built") autorebuild_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') error_addresses = ['*****@*****.**'] p = SendMailPlugin(None, WF(), send_on=[AF], error_addresses=error_addresses) flexmock(p).should_receive('_should_send').with_args(True, False, False).and_return(True) flexmock(p).should_receive('_get_receivers_list').and_raise(RuntimeError()) flexmock(p).should_receive('_send_mail').with_args(error_addresses, six.text_type, six.text_type) p.run()
def test_run_fails_to_obtain_receivers(self): class WF(object): build_failed = True autorebuild_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') error_addresses = ['*****@*****.**'] p = SendMailPlugin(None, WF(), send_on=[AF], error_addresses=error_addresses) flexmock(p).should_receive('_should_send').with_args(True, False, False).and_return(True) flexmock(p).should_receive('_get_receivers_list').and_raise(RuntimeError()) flexmock(p).should_receive('_send_mail').with_args(error_addresses, six.text_type, six.text_type) p.run()
def test_run_fails_to_obtain_receivers(self, reactor_config_map): # noqa class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} plugin_workspace = {} error_addresses = ['*****@*****.**'] workflow = WF() mock_store_metadata_results(workflow) if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'error_addresses': ['*****@*****.**'], } 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', send_on=[AF], error_addresses=error_addresses) (flexmock(p).should_receive('_should_send').with_args( True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_raise( RuntimeError()) flexmock(p).should_receive('_fetch_log_files').and_return(None) flexmock(p).should_receive('_get_image_name_and_repos').and_return( ('foobar', ['foo/bar:baz', 'foo/bar:spam'])) flexmock(p).should_receive('_send_mail').with_args( error_addresses, six.text_type, six.text_type, None) p.run()
def test_run_ok(self, tmpdir): # noqa class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} plugin_workspace = {} source = mock_source() builder = mock_builder() with open(os.path.join(str(tmpdir), 'Dockerfile'), 'wt') as df: df.write(MOCK_DOCKERFILE) setattr(builder, 'df_path', df.name) receivers = ['*****@*****.**', '*****@*****.**'] workflow = WF() mock_store_metadata_results(workflow) 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}) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(None, workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[AF]) (flexmock(p).should_receive('_should_send') .with_args(True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_fetch_log_files').and_return(None) flexmock(p).should_receive('_send_mail').with_args(receivers, str, str, None) p.run()
def test_fails_with_unknown_states(self, workflow): smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.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, smtp_host='smtp.bar.com', from_address='*****@*****.**', send_on=['unknown_state', MS]) with pytest.raises(PluginFailedException) as e: p.run() assert str(e.value) == 'Unknown state(s) "unknown_state" for sendmail plugin'
def test_run_ok(self, tmpdir, reactor_config_map): # noqa class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} plugin_workspace = {} source = mock_source() builder = mock_builder() with open(os.path.join(str(tmpdir), 'Dockerfile'), 'wt') as df: df.write(MOCK_DOCKERFILE) setattr(builder, 'df_path', df.name) receivers = ['*****@*****.**', '*****@*****.**'] workflow = WF() mock_store_metadata_results(workflow) 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', send_on=[AF]) (flexmock(p).should_receive('_should_send') .with_args(True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(p).should_receive('_fetch_log_files').and_return(None) flexmock(p).should_receive('_send_mail').with_args(receivers, six.text_type, six.text_type, None) p.run()
def test_run_fails_to_obtain_receivers(self, reactor_config_map): # noqa class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} plugin_workspace = {} source = mock_source() error_addresses = ['*****@*****.**'] workflow = WF() mock_store_metadata_results(workflow) if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'error_addresses': ['*****@*****.**'], } 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', send_on=[AF], error_addresses=error_addresses) (flexmock(p).should_receive('_should_send') .with_args(True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_raise(RuntimeError()) flexmock(p).should_receive('_fetch_log_files').and_return(None) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) flexmock(p).should_receive('_send_mail').with_args(error_addresses, six.text_type, six.text_type, None) p.run()
def test_run_invalid_receivers(self, caplog): # noqa class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} plugin_workspace = {} source = mock_source() error_addresses = ['*****@*****.**'] workflow = WF() mock_store_metadata_results(workflow) smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.bar.com', 'error_addresses': ['*****@*****.**'], } workflow.plugin_workspace[ReactorConfigPlugin.key] = {} workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig({'version': 1, 'smtp': smtp_map}) add_koji_map_in_workflow(workflow, hub_url='/', root_url='', ssl_certs_dir='/certs') p = SendMailPlugin(None, workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[AF], error_addresses=error_addresses) (flexmock(p).should_receive('_should_send') .with_args(True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return([]) flexmock(p).should_receive('_fetch_log_files').and_return(None) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) p.run() assert 'no valid addresses in requested addresses. Doing nothing' in caplog.text
def test_run_does_nothing_if_conditions_not_met(self): class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True p = SendMailPlugin(None, WF(), from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[MS]) (flexmock(p).should_receive('_should_send').with_args( True, False, False, False).and_return(False)) flexmock(p).should_receive('_get_receivers_list').times(0) flexmock(p).should_receive('_send_mail').times(0) p.run()
def test_run_does_nothing_if_conditions_not_met(self, workflow): workflow.data.plugin_failed = True smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.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', send_on=[MS]) (flexmock(p).should_receive('_should_send') .with_args(False, False).and_return(False)) flexmock(p).should_receive('_get_receivers_list').times(0) flexmock(p).should_receive('_send_mail').times(0) p.run()
def test_fails_with_unknown_states(self, reactor_config_map): # noqa class WF(object): exit_results = {} plugin_workspace = {} workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.com', } workflow.plugin_workspace[ReactorConfigPlugin.key] = {} workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig({'version': 1, 'smtp': smtp_map}) p = SendMailPlugin(None, workflow, smtp_host='smtp.bar.com', from_address='*****@*****.**', send_on=['unknown_state', MS]) with pytest.raises(PluginFailedException) as e: p.run() assert str(e.value) == 'Unknown state(s) "unknown_state" for sendmail plugin'
def test_fails_with_unknown_states(self, reactor_config_map): # noqa class WF(object): exit_results = {} plugin_workspace = {} workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.com', } workflow.plugin_workspace[ReactorConfigPlugin.key] = {} workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig({'version': 1, 'smtp': smtp_map}) p = SendMailPlugin(None, workflow, smtp_host='smtp.bar.com', from_address='*****@*****.**', send_on=['unknown_state', MS]) with pytest.raises(PluginFailedException) as e: p.run() assert str(e.value) == 'Unknown state(s) "unknown_state" for sendmail plugin'
def test_run_ok_and_send(self, monkeypatch, reactor_config_map): # noqa class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} plugin_workspace = {} source = mock_source() class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass monkeypatch.setenv("BUILD", json.dumps({ 'metadata': { 'labels': { 'koji-task-id': MOCK_KOJI_TASK_ID, }, 'name': {}, } })) workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.com', } workflow.plugin_workspace[ReactorConfigPlugin.key] = {} workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig({'version': 1, 'smtp': smtp_map}) receivers = ['*****@*****.**', '*****@*****.**'] fake_logs = [LogEntry(None, 'orchestrator'), LogEntry(None, 'orchestrator line 2'), LogEntry('x86_64', 'Hurray for bacon: \u2017'), LogEntry('x86_64', 'line 2')] p = SendMailPlugin(None, workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[AF]) (flexmock(p).should_receive('_should_send') .with_args(True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(OSBS).should_receive('get_orchestrator_build_logs').and_return(fake_logs) flexmock(p).should_receive('_get_image_name_and_repos').and_return(('foobar', ['foo/bar:baz', 'foo/bar:spam'])) smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) p.run()
def test_fails_with_unknown_states(self): p = SendMailPlugin(None, None, send_on=['unknown_state', MS]) with pytest.raises(PluginFailedException) as e: p.run() assert str(e.value) == 'Unknown state(s) "unknown_state" for sendmail plugin'
def test_run_ok_and_send(self, monkeypatch, reactor_config_map): # noqa class TagConf(object): unique_images = [] class WF(object): autorebuild_canceled = False build_canceled = False prebuild_results = {CheckAndSetRebuildPlugin.key: True} image = util.ImageName.parse('repo/name') build_process_failed = True tag_conf = TagConf() exit_results = {} plugin_workspace = {} class SMTP(object): def sendmail(self, from_addr, to, msg): pass def quit(self): pass monkeypatch.setenv( "BUILD", json.dumps({ 'metadata': { 'labels': { 'koji-task-id': MOCK_KOJI_TASK_ID, }, 'name': {}, } })) workflow = WF() if reactor_config_map: smtp_map = { 'from_address': '*****@*****.**', 'host': 'smtp.spam.com', } workflow.plugin_workspace[ReactorConfigPlugin.key] = {} workflow.plugin_workspace[ReactorConfigPlugin.key][WORKSPACE_CONF_KEY] =\ ReactorConfig({'version': 1, 'smtp': smtp_map}) receivers = ['*****@*****.**', '*****@*****.**'] fake_logs = [ LogEntry(None, 'orchestrator'), LogEntry(None, 'orchestrator line 2'), LogEntry('x86_64', 'Hurray for bacon: \u2017'), LogEntry('x86_64', 'line 2') ] p = SendMailPlugin(None, workflow, from_address='*****@*****.**', smtp_host='smtp.spam.com', send_on=[AF]) (flexmock(p).should_receive('_should_send').with_args( True, False, False, False).and_return(True)) flexmock(p).should_receive('_get_receivers_list').and_return(receivers) flexmock(OSBS).should_receive( 'get_orchestrator_build_logs').and_return(fake_logs) flexmock(p).should_receive('_get_image_name_and_repos').and_return( ('foobar', ['foo/bar:baz', 'foo/bar:spam'])) smtp_inst = SMTP() flexmock(smtplib).should_receive('SMTP').and_return(smtp_inst) p.run()
def test_fails_with_unknown_states(self): p = SendMailPlugin(None, None, send_on=['unknown_state', MS]) with pytest.raises(PluginFailedException) as e: p.run() assert str(e.value) == 'Unknown state(s) "unknown_state" for sendmail plugin'