Ejemplo n.º 1
0
    def test_run_invalid_receivers(self, caplog, workflow):
        MockEnv(workflow).mock_build_outcome(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
Ejemplo n.º 2
0
    def test_run_ok_and_send(self, workflow):
        MockEnv(workflow).mock_build_outcome(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()
Ejemplo n.º 3
0
    def test_run_ok(self, tmpdir, workflow, source_dir):
        MockEnv(workflow).mock_build_outcome(failed=True)
        receivers = ['*****@*****.**', '*****@*****.**']

        mock_dockerfile(workflow)
        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()
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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'
Ejemplo n.º 6
0
    def test_run_does_nothing_if_conditions_not_met(self, workflow):
        MockEnv(workflow).mock_build_outcome(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()