Esempio n. 1
0
def test_slack_instance_should_get_im_messages_without_channel(mock_webclient):
    def conversations_history(channel, limit=None):
        if channel == 'CH234':
            messages = [{
                'user': '******',
                'text': f'm{i}',
                'ts': f'{45.5 + i}'
            } for i in range(limit)]
            response = {'messages': messages}
            return response
        else:
            return None

    mock_webclient.conversations_history.side_effect = conversations_history

    def mock_conversations_list(types):
        if 'im' in types.split(','):
            return {'channels': []}
        else:
            return None

    mock_webclient.conversations_list.side_effect = mock_conversations_list

    slack = setup_slack()

    messages = slack.get_im_messages('dummyuser')
    assert len(messages) == 0
Esempio n. 2
0
def test_slack_instance_should_get_im_messages_w_count(slack, mock_webclient):
    def conversations_history(channel, limit=None):
        if channel == 'CH234':
            messages = [{'user': '******', 'text': f'message{i}'}
                        for i in range(limit)]
            response = {'messages': messages}
            return response
        else:
            return None

    mock_webclient.conversations_history.side_effect = conversations_history

    messages = slack.get_im_messages('dummyuser', count=3)
    assert len(messages) == 3