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] == '>'
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)
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
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] == '>'
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
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')
def test_get_attachment_color(): srv = Service({}) assert type(srv.get_attachment_color({'type': 'story'})) == str
def test_get_attachment_color_empty(): srv = Service({}) assert type(srv.get_attachment_color()) == str