Пример #1
0
def test_format_item_link():
    srv = Service({})
    item = {'short_url': '', 'title': '', 'number': 1}
    link = srv.format_item_link(item)

    assert type(link) == str
    assert link[0] == '<'
    assert link[-1] == '>'
Пример #2
0
def test_get_post_data(payload):
    model = payload['model'].lower()
    srv = Service({})
    with patch.object(srv, 'get_%s_attachment' % model) as mock_get_attachment:
        mock_get_attachment.return_value = {}
        post_data = srv.get_post_data(payload)
        assert post_data.has_key('attachments')
        assert post_data.has_key('icon_url')
        mock_get_attachment.assert_called_with(payload)
Пример #3
0
def test_get_post_data(payload):
    model = payload['model'].lower()
    srv = Service({})
    with patch.object(srv, 'get_%s_attachment' % model) as mock_get_attachment:
        mock_get_attachment.return_value = {}
        post_data = srv.get_post_data(payload)
        assert post_data.has_key('attachments')
        assert post_data.has_key('icon_url')
        mock_get_attachment.assert_called_with(payload)
Пример #4
0
def test_slack_requires_url(payload):
    with patch('urllib2.Request') as mock_urllib2_request:
        with patch('urllib2.urlopen') as mock_urllib2_urlopen:
            mock_request = Mock()
            mock_urllib2_request.return_value = mock_request

            service = SlackService({})
            service.send(payload)

            assert not mock_urllib2_request.called
            assert not mock_urllib2_urlopen.called
Пример #5
0
def test_slack_requires_url(payload):
    with patch('urllib2.Request') as mock_urllib2_request:
        with patch('urllib2.urlopen') as mock_urllib2_urlopen:
            mock_request = Mock()
            mock_urllib2_request.return_value = mock_request

            service = SlackService({})
            service.send(payload)

            assert not mock_urllib2_request.called
            assert not mock_urllib2_urlopen.called
Пример #6
0
def test_format_item_link():
    srv = Service({})
    item = {
        'short_url': '',
        'title': '',
        'number' : 1
    }
    link = srv.format_item_link(item)

    assert type(link) ==  str
    assert link[0] == '<'
    assert link[-1] == '>'
Пример #7
0
def test_slack_sends(payload):
    options = {
        'url': 'https://something.slack.com/services/hooks/incoming-webhook?token=sometoken'
    }

    with patch('urllib2.Request') as mock_urllib2_request:
        with patch('urllib2.urlopen') as mock_urllib2_urlopen:
            mock_request = Mock()
            mock_urllib2_request.return_value = mock_request

            service = SlackService(options)
            service.send(payload)

            assert mock_urllib2_request.called
            assert mock_urllib2_request.call_args[0][0] == options['url']
            mock_urllib2_urlopen.call_args[0][0] == mock_request
Пример #8
0
def test_get_attachment(payload):
    srv = Service({})
    model = payload['model'].lower()
    method = 'get_%s_attachment' % model
    attachment = getattr(srv, method)(payload)
    assert type(attachment) == dict
    assert attachment.has_key('text')
Пример #9
0
def test_slack_sends(payload):
    options = {
        'url':
        'https://something.slack.com/services/hooks/incoming-webhook?token=sometoken'
    }

    with patch('urllib2.Request') as mock_urllib2_request:
        with patch('urllib2.urlopen') as mock_urllib2_urlopen:
            mock_request = Mock()
            mock_urllib2_request.return_value = mock_request

            service = SlackService(options)
            service.send(payload)

            assert mock_urllib2_request.called
            assert mock_urllib2_request.call_args[0][0] == options['url']
            mock_urllib2_urlopen.call_args[0][0] == mock_request
Пример #10
0
def test_get_attachment_color():
    srv = Service({})
    assert type(srv.get_attachment_color({'type': 'story'})) == str
Пример #11
0
def test_get_attachment_color_empty():
    srv = Service({})
    assert type(srv.get_attachment_color()) == str
Пример #12
0
def test_get_attachment_color():
    srv = Service({})
    assert type(srv.get_attachment_color({'type': 'story'})) == str
Пример #13
0
def test_get_attachment_color_empty():
    srv = Service({})
    assert type(srv.get_attachment_color()) == str