Пример #1
0
def test_send(slack_url):
    ''' Test slack.send(). '''
    notify_params = dict(
        branch_url='http://branch-url',
        branch='temp',
        commit='tttt',
        commit_url='http://commit-url',
        public_url='http://public-url',
        host='test-notify-deploying-host',
        repository_url='http://repository-url',
        project_name='project-name',
        server_name='server-name',
        server_link='http://server-link',
        user='******',
    )

    payload = {
        'attachments': [{
            'color': 'good',
            'text':
            'user is deploying <http://repository-url|project-name>:<http://branch-url|temp> (<http://commit-url|tttt>) to <http://public-url|server-name> server.',
            'mrkdwn_in': ['text']
        }]
    }

    with patch('requests.post') as mock_post:
        slack.send(DEPLOYMENT_STARTED, **notify_params)
        mock_post.assert_called_once_with(slack_url, json=payload)
Пример #2
0
def test_send_deployment_started_with_no_repository_url(slack_url):
    ''' Test deployment started notification with no repository url. '''
    notify_params = dict(
        branch='temp',
        commit='tttt',
        commit_url=None,
        branch_url=None,
        repository_url=None,
        public_url='http://public-url',
        host='test-notify-deploying-host',
        project_name='project-name',
        server_name='server-name',
        server_link='http://server-link',
        user='******',
    )

    payload = {
        'attachments': [{
            'color': 'good',
            'text':
            'user is deploying project-name:temp (tttt) to <http://public-url|server-name> server.',
            'mrkdwn_in': ['text']
        }]
    }

    with patch('requests.post') as mock_post:
        slack.send(DEPLOYMENT_STARTED, **notify_params)
        mock_post.assert_called_once_with(slack_url, json=payload)
Пример #3
0
def test_notity_deployed_with_no_branch_name(slack_url):
    '''
    Test slack.notify_deployed() doesn't show the branch link,
    if branch name is not provided.
    '''

    notify_params = dict(public_url='http://public-url',
                         host='test-notify-deployed-host',
                         commit='tttt',
                         commit_url='http://commit-url',
                         repository_url='http://repository-url',
                         project_name='project-name',
                         server_name='server-name',
                         server_link='http://server-link',
                         user='******')
    payload = {
        'attachments': [{
            'color': '#764FA5',
            'text':
            'user finished deploying <http://repository-url|project-name> (<http://commit-url|tttt>) to <http://public-url|server-name> server.',
            'mrkdwn_in': ['text']
        }]
    }

    with patch('requests.post') as mock_post:
        slack.send(DEPLOYMENT_FINISHED, **notify_params)
        mock_post.assert_called_once_with(slack_url, json=payload)
Пример #4
0
def test_notity_deployment_started_no_links_at_all(slack_url):
    ''' Test deployment started notification with no links or urls at all. '''
    notify_params = dict(
        project_name='project-name',
        server_name='staging',
        user='******',
    )

    payload = {
        'attachments': [{
            'color': 'good',
            'text': 'user is deploying project-name to staging server.',
            'mrkdwn_in': ['text']
        }]
    }

    with patch('requests.post') as mock_post:
        slack.send(DEPLOYMENT_STARTED, **notify_params)
        mock_post.assert_called_once_with(slack_url, json=payload)
Пример #5
0
def test_notity_deployment_started_with_no_commit_no_branch(slack_url):
    ''' Test sending deployment started notification with no commit and no branch. '''
    notify_params = dict(public_url='http://public-url',
                         host='test-notify-deployed-host',
                         repository_url='http://repository-url',
                         project_name='project-name',
                         server_name='server-name',
                         server_link='http://server-link',
                         user='******')
    payload = {
        'attachments': [{
            'color': 'good',
            'text':
            'user is deploying <http://repository-url|project-name> to <http://public-url|server-name> server.',
            'mrkdwn_in': ['text']
        }]
    }

    with patch('requests.post') as mock_post:
        slack.send(DEPLOYMENT_STARTED, **notify_params)
        mock_post.assert_called_once_with(slack_url, json=payload)
Пример #6
0
def test_send_running_script_finished_notification(slack_url):
    ''' Test send() sends RUNNING_SCRIPT_FINISHED notfication. '''
    notify_params = dict(public_url='http://public-url',
                         host='test-notify-deploying-host',
                         repository_url='http://repository-url',
                         project_name='project-name',
                         server_name='stage',
                         server_link='http://server-link',
                         script='migration',
                         user='******')

    payload = {
        'attachments': [{
            'color': '#764FA5',
            'text':
            'user finished running <http://repository-url|project-name>:migration on <http://public-url|stage> server.',
            'mrkdwn_in': ['text']
        }]
    }

    with patch('requests.post') as mock_post:
        slack.send(RUNNING_SCRIPT_FINISHED, **notify_params)
        mock_post.assert_called_once_with(slack_url, json=payload)
Пример #7
0
def test_notity_deployed_with_no_commit(slack_url):
    ''' Test sending deployment finished notification with no commit. '''
    notify_params = dict(branch_url='http://branch-url',
                         branch='temp',
                         public_url='http://public-url',
                         host='test-notify-deployed-host',
                         repository_url='http://repository-url',
                         project_name='project-name',
                         server_name='server-name',
                         server_link='http://server-link',
                         user='******')
    payload = {
        'attachments': [{
            'color': '#764FA5',
            'text':
            'user finished deploying <http://repository-url|project-name>:<http://branch-url|temp> to <http://public-url|server-name> server.',
            'mrkdwn_in': ['text']
        }]
    }

    with patch('requests.post') as mock_post:
        slack.send(DEPLOYMENT_FINISHED, **notify_params)
        mock_post.assert_called_once_with(slack_url, json=payload)