Exemplo n.º 1
0
def test_slack_deploy_notifier_doesnt_notify_on_deploy_info_flags(
        mock_get_authors, mock_client):
    fake_psc = mock.create_autospec(PaastaSlackClient)
    mock_client.return_value = fake_psc
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    sdn = mark_for_deployment.SlackDeployNotifier(
        service='testservice',
        deploy_info={
            'pipeline': [
                {
                    'step': 'test_deploy_group',
                    'slack_notify': True,
                    'notify_after_mark': False,
                    'notify_after_good_deploy': False,
                    'notify_after_auto_rollback': False,
                    'notify_after_abort': False,
                },
            ],
        },
        deploy_group='test_deploy_group',
        commit='newcommit',
        old_commit='oldcommit',
        git_url="foo",
    )
    assert sdn.notify_after_mark(ret=1) is None
    assert sdn.notify_after_mark(ret=0) is None
    assert sdn.notify_after_good_deploy() is None
    assert sdn.notify_after_auto_rollback() is None
    assert sdn.notify_after_abort() is None
    assert fake_psc.post.call_count == 0, fake_psc.post.call_args
Exemplo n.º 2
0
def test_slack_deploy_notifier_notifies_on_deploy_info_flags(
        mock_get_authors, mock_client):
    fake_psc = mock.create_autospec(PaastaSlackClient)
    fake_psc.post.return_value = [{'ok': True, 'message': {'ts': 1234}}]
    mock_client.return_value = fake_psc
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    sdn = mark_for_deployment.SlackDeployNotifier(
        service='testservice',
        deploy_info={
            'pipeline': [
                {
                    'step': 'test_deploy_group',
                    'notify_after_mark': True,
                    'notify_after_good_deploy': True,
                    'notify_after_auto_rollback': True,
                    'notify_after_abort': True,
                },
            ],
            'slack_channels': ['#webcore', '#webcore2'],
        },
        deploy_group='test_deploy_group',
        commit='newcommit',
        old_commit='oldcommit',
        git_url="foo",
    )
    assert sdn.notify_after_mark(ret=1) is None
    assert sdn.notify_after_mark(ret=0) is None
    assert sdn.notify_after_good_deploy() is None
    assert sdn.notify_after_auto_rollback() is None
    assert sdn.notify_after_abort() is None
    assert fake_psc.post.call_count > 0, fake_psc.post.call_args
    assert "Jenkins" or "Run by" in sdn.get_url_message()
Exemplo n.º 3
0
def test_slack_deploy_notifier_doesnt_notify_on_same_commit(mock_get_authors, mock_client):
    fake_psc = mock.create_autospec(PaastaSlackClient)
    mock_client.return_value = fake_psc
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    sdn = mark_for_deployment.SlackDeployNotifier(
        service='testservice',
        deploy_info={
            'pipeline':
            [
                {'step': 'test_deploy_group', 'slack_notify': True, },
            ],
            'slack_channels': ['#webcore', '#webcore2'],
        },
        deploy_group='test_deploy_group',
        commit='samecommit',
        old_commit='samecommit',
        git_url="foo",
    )
    assert sdn.notify_after_mark(ret=1) is None
    assert sdn.notify_after_mark(ret=0) is None
    assert sdn.notify_after_good_deploy() is None
    assert sdn.notify_after_auto_rollback() is None
    assert sdn.notify_after_abort() is None
    assert fake_psc.post.call_count == 0, fake_psc.post.call_args
    assert sdn.get_authors_to_be_notified() == "Authors: <@fakeuser1>, <@fakeuser2>"
Exemplo n.º 4
0
def test_slack_deploy_notifier(mock_get_authors, mock_client):
    fake_psc = mock.create_autospec(PaastaSlackClient)
    fake_psc.post.return_value = [{'ok': True, 'message': {'ts': 1234}}]
    mock_client.return_value = fake_psc
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    sdn = mark_for_deployment.SlackDeployNotifier(
        service='testservice',
        deploy_info={
            'pipeline': [
                {
                    'step': 'test_deploy_group',
                    'slack_notify': True,
                },
            ],
            'slack_channels': ['#webcore', '#webcore2'],
        },
        deploy_group='test_deploy_group',
        commit='newcommit',
        old_commit='oldcommit',
        git_url="foo",
    )
    assert sdn.notify_after_mark(ret=1) is None
    assert sdn.notify_after_mark(ret=0) is None
    assert sdn.notify_after_good_deploy() is None
    assert sdn.notify_after_auto_rollback() is None
    assert sdn.notify_after_abort() is None
    assert fake_psc.post.call_count > 0, fake_psc.post.call_args

    with mock.patch.dict(
            os.environ,
        {'BUILD_URL': 'https://www.yelp.com'},
            clear=True,
    ):
        assert sdn.get_url_message(
        ) == '<https://www.yelp.com/consoleFull|Jenkins Job>'
def test_slack_deploy_notifier(mock_get_authors, mock_client):
    fake_psc = mock.create_autospec(PaastaSlackClient)
    mock_client.return_value = fake_psc
    mock_get_authors.return_value = 0, "fakeuser1 fakeuser2"
    sdn = mark_for_deployment.SlackDeployNotifier(
        service='testservice',
        deploy_info={
            'pipeline': [
                {
                    'step': 'test_deploy_group',
                    'slack_notify': True,
                },
            ],
        },
        deploy_group='test_deploy_group',
        commit='newcommit',
        old_commit='oldcommit',
        git_url="foo",
    )
    assert sdn.notify_after_mark(ret=1) is None
    assert sdn.notify_after_mark(ret=0) is None
    assert sdn.notify_after_good_deploy() is None
    assert sdn.notify_after_auto_rollback() is None
    assert sdn.notify_after_abort() is None
    assert fake_psc.post.call_count >= 0, fake_psc.post.call_args
    assert sdn.get_authors_to_be_notified(
    ) == "Pinging authors: <@fakeuser1>, <@fakeuser2>"
    assert "Jenkins" or "Run by" in sdn.get_url_message()