Exemplo n.º 1
0
async def test_slack_api_conversations_info(bot):
    channel_id = "C1234"

    await bot.api.conversations.info(
        channel_id,
        include_locale=False,
        include_num_members=True,
    )
    call = bot.call_queue.pop()
    assert call.method == "conversations.info"
    assert call.data == {
        "channel": channel_id,
        "include_locale": bool2str(False),
        "include_num_members": bool2str(True),
    }

    await bot.api.conversations.info(
        channel_id,
        include_locale=False,
        include_num_members=True,
    )
    call = bot.call_queue.pop()
    assert call.method == "conversations.info"
    assert call.data == {
        "channel": channel_id,
        "include_locale": bool2str(False),
        "include_num_members": bool2str(True),
    }
Exemplo n.º 2
0
async def test_slack_api_chat_delete():
    bot = FakeBot()
    channel = bot.add_channel('C4567', 'test')
    channel_id = 'C1234'

    ts = '1234.56'
    alternative_token = '1234567890'

    await bot.api.chat.delete(channel_id, ts, False)

    call = bot.call_queue.pop()
    assert call.method == 'chat.delete'
    assert call.data == {
        'channel': channel_id,
        'ts': ts,
        'as_user': bool2str(False),
    }
    assert call.token is None

    await bot.api.chat.delete(channel, ts, True, token=alternative_token)

    call = bot.call_queue.pop()
    assert call.method == 'chat.delete'
    assert call.data == {
        'channel': channel.id,
        'ts': ts,
        'as_user': bool2str(True),
    }
    assert call.token == alternative_token
Exemplo n.º 3
0
async def test_slack_api_chat_delete(bot):
    channel_id = "C1234"

    ts = "1234.56"
    alternative_token = "1234567890"

    await bot.api.chat.delete(channel_id, ts, False)

    call = bot.call_queue.pop()
    assert call.method == "chat.delete"
    assert call.data == {
        "channel": channel_id,
        "ts": ts,
        "as_user": bool2str(False),
    }
    assert call.token is None

    await bot.api.chat.delete(channel_id, ts, True, token=alternative_token)

    call = bot.call_queue.pop()
    assert call.method == "chat.delete"
    assert call.data == {
        "channel": channel_id,
        "ts": ts,
        "as_user": bool2str(True),
    }
    assert call.token == alternative_token
Exemplo n.º 4
0
async def test_slack_api_conversations_info(bot):
    channel = bot.add_channel('C4567', 'test')
    channel_id = 'C1234'

    await bot.api.conversations.info(
        channel_id,
        include_locale=False,
        include_num_members=True,
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.info'
    assert call.data == {
        'channel': channel_id,
        'include_locale': bool2str(False),
        'include_num_members': bool2str(True),
    }

    await bot.api.conversations.info(
        channel,
        include_locale=False,
        include_num_members=True,
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.info'
    assert call.data == {
        'channel': channel.id,
        'include_locale': bool2str(False),
        'include_num_members': bool2str(True),
    }
Exemplo n.º 5
0
async def test_slack_api_conversations_list():
    cursor = '1234asdf'
    exclude_archived = False
    exclude_members = False
    limit = 12
    types = 'private_channel'

    bot = FakeBot()

    await bot.api.conversations.list(
        cursor,
        exclude_archived,
        exclude_members,
        limit,
        types,
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.list'
    assert call.data == {
        'cursor': cursor,
        'exclude_archived': bool2str(exclude_archived),
        'exclude_members': bool2str(exclude_members),
        'limit': '12',
        'types': types,
    }
Exemplo n.º 6
0
async def test_slack_api_groups_list():
    bot = FakeBot()

    await bot.api.groups.list()
    call = bot.call_queue.pop()
    assert call.method == 'groups.list'
    assert call.data == {
        'exclude_archived': bool2str(True),
        'exclude_members': bool2str(True),
    }
Exemplo n.º 7
0
async def test_slack_api_users_list():
    bot = FakeBot()

    await bot.api.users.list(
        curser='asdf1234', include_locale=True, limit=20, presence=True,
    )

    call = bot.call_queue.pop()
    assert call.method == 'users.list'
    assert call.data == {
        'cursor': 'asdf1234',
        'include_locale': bool2str(True),
        'limit': '20',
        'presence': bool2str(True),
    }
Exemplo n.º 8
0
async def test_slack_api_users_list(bot):
    await bot.api.users.list(
        curser="asdf1234",
        include_locale=True,
        limit=20,
        presence=True,
    )

    call = bot.call_queue.pop()
    assert call.method == "users.list"
    assert call.data == {
        "cursor": "asdf1234",
        "include_locale": bool2str(True),
        "limit": "20",
        "presence": bool2str(True),
    }
Exemplo n.º 9
0
async def test_slack_api_conversations_replies(bot):
    channel = bot.add_channel('C4567', 'test')
    channel_id = 'C1234'
    ts = '123456.7'

    await bot.api.conversations.replies(
        channel_id,
        ts,
        cursor='asdf',
        inclusive=True,
        latest='123',
        limit=42,
        oldest='456',
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.replies'
    assert call.data == {
        'channel': channel_id,
        'ts': ts,
        'cursor': 'asdf',
        'inclusive': bool2str(True),
        'latest': '123',
        'limit': '42',
        'oldest': '456',
    }
    await bot.api.conversations.replies(
        channel,
        ts,
        cursor='asdf',
        inclusive=True,
        latest='123',
        limit=42,
        oldest='456',
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.replies'
    assert call.data == {
        'channel': channel.id,
        'ts': ts,
        'cursor': 'asdf',
        'inclusive': bool2str(True),
        'latest': '123',
        'limit': '42',
        'oldest': '456',
    }
Exemplo n.º 10
0
async def test_slack_api_channels_list():
    cursor = '1234asdf'
    exclude_archived = False
    exclude_members = False
    limit = 12

    bot = FakeBot()

    await bot.api.channels.list(cursor, exclude_archived, exclude_members,
                                limit)
    call = bot.call_queue.pop()
    assert call.method == 'channels.list'
    assert call.data == {
        'cursor': cursor,
        'exclude_archived': bool2str(exclude_archived),
        'exclude_members': bool2str(exclude_members),
        'limit': '12',
    }
Exemplo n.º 11
0
async def test_slack_api_conversations_replies(bot):
    channel_id = "C1234"
    ts = "123456.7"

    await bot.api.conversations.replies(
        channel_id,
        ts,
        cursor="asdf",
        inclusive=True,
        latest="123",
        limit=42,
        oldest="456",
    )
    call = bot.call_queue.pop()
    assert call.method == "conversations.replies"
    assert call.data == {
        "channel": channel_id,
        "ts": ts,
        "cursor": "asdf",
        "inclusive": bool2str(True),
        "latest": "123",
        "limit": "42",
        "oldest": "456",
    }
    await bot.api.conversations.replies(
        channel_id,
        ts,
        cursor="asdf",
        inclusive=True,
        latest="123",
        limit=42,
        oldest="456",
    )
    call = bot.call_queue.pop()
    assert call.method == "conversations.replies"
    assert call.data == {
        "channel": channel_id,
        "ts": ts,
        "cursor": "asdf",
        "inclusive": bool2str(True),
        "latest": "123",
        "limit": "42",
        "oldest": "456",
    }
Exemplo n.º 12
0
async def test_slack_api_channels_history():
    channel_id = 'C1234'
    channel = PublicChannel(id='C4567')

    bot = FakeBot()

    await bot.api.channels.history(
        channel_id,
        count=1234,
        inclusive=True,
        latest='123',
        oldest='456',
        unreads=False,
    )
    call = bot.call_queue.pop()
    assert call.method == 'channels.history'
    assert call.data == {
        'channel': channel_id,
        'count': '1234',
        'inclusive': bool2str(True),
        'latest': '123',
        'oldest': '456',
        'unreads': bool2str(False),
    }
    await bot.api.channels.history(
        channel,
        count=1234,
        inclusive=True,
        latest='123',
        oldest='456',
        unreads=False,
    )
    call = bot.call_queue.pop()
    assert call.method == 'channels.history'
    assert call.data == {
        'channel': channel.id,
        'count': '1234',
        'inclusive': bool2str(True),
        'latest': '123',
        'oldest': '456',
        'unreads': bool2str(False),
    }
Exemplo n.º 13
0
async def test_slack_api_groups_info():
    bot = FakeBot()
    group = bot.add_private_channel('G2', 'secret')
    group_id = 'G1'

    await bot.api.groups.info(group_id)
    call = bot.call_queue.pop()
    assert call.method == 'groups.info'
    assert call.data == {
        'channel': 'G1',
        'include_locale': bool2str(False),
    }

    await bot.api.groups.info(group)
    call = bot.call_queue.pop()
    assert call.method == 'groups.info'
    assert call.data == {
        'channel': 'G2',
        'include_locale': bool2str(False),
    }
Exemplo n.º 14
0
async def test_slack_api_conversations_info():
    bot = FakeBot()
    channel = bot.add_channel('C4567', 'test')
    channel_id = 'C1234'

    await bot.api.conversations.info(channel_id)
    call = bot.call_queue.pop()
    assert call.method == 'conversations.info'
    assert call.data == {
        'channel': channel_id,
        'include_locale': bool2str(False),
    }

    await bot.api.conversations.info(channel)
    call = bot.call_queue.pop()
    assert call.method == 'conversations.info'
    assert call.data == {
        'channel': channel.id,
        'include_locale': bool2str(False),
    }
Exemplo n.º 15
0
async def test_slack_api_channels_info():
    channel_id = 'C1234'
    channel = PublicChannel(id='C4567')

    bot = FakeBot()

    await bot.api.channels.info(channel_id)
    call = bot.call_queue.pop()
    assert call.method == 'channels.info'
    assert call.data == {
        'channel': channel_id,
        'include_locale': bool2str(False),
    }

    await bot.api.channels.info(channel)
    call = bot.call_queue.pop()
    assert call.method == 'channels.info'
    assert call.data == {
        'channel': channel.id,
        'include_locale': bool2str(False),
    }
Exemplo n.º 16
0
async def test_slack_api_conversations_open():
    bot = FakeBot()
    channel_id = 'C1234'
    channel = bot.add_channel(channel_id, 'test')
    user_id = 'U1234'
    user = bot.add_user(user_id, 'tester')
    user2_id = 'U5678'
    bot.add_user(user2_id, 'tester2')
    return_im = True

    with pytest.raises(ValueError):
        await bot.api.conversations.open(
            channel=channel_id,
            users=[user_id],
        )
    with pytest.raises(ValueError):
        await bot.api.conversations.open()

    await bot.api.conversations.open(
        channel=channel_id,
        return_im=return_im,
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.open'
    assert call.data == {
        'channel': channel_id,
        'return_im': bool2str(return_im),
    }

    await bot.api.conversations.open(
        channel=channel,
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.open'
    assert call.data == {
        'channel': channel_id,
    }

    await bot.api.conversations.open(
        users=[user, user2_id],
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.open'
    assert call.data == {
        'users': f'{user_id},{user2_id}',
    }
Exemplo n.º 17
0
async def test_slack_api_conversations_list(bot):
    cursor = '1234asdf'
    exclude_archived = False
    limit = 12
    types = 'private_channel'
    team_id = 'T1'

    await bot.api.conversations.list(
        cursor=cursor,
        exclude_archived=exclude_archived,
        limit=limit,
        team_id=team_id,
        types=types,
    )
    call = bot.call_queue.pop()
    assert call.method == 'conversations.list'
    assert call.data == {
        'cursor': cursor,
        'exclude_archived': bool2str(exclude_archived),
        'limit': str(limit),
        'team_id': team_id,
        'types': types,
    }
Exemplo n.º 18
0
async def test_slack_api_conversations_list(bot):
    cursor = "1234asdf"
    exclude_archived = False
    limit = 12
    types = "private_channel"
    team_id = "T1"

    await bot.api.conversations.list(
        cursor=cursor,
        exclude_archived=exclude_archived,
        limit=limit,
        team_id=team_id,
        types=types,
    )
    call = bot.call_queue.pop()
    assert call.method == "conversations.list"
    assert call.data == {
        "cursor": cursor,
        "exclude_archived": bool2str(exclude_archived),
        "limit": str(limit),
        "team_id": team_id,
        "types": types,
    }
Exemplo n.º 19
0
async def test_slack_api_conversations_open(bot):
    channel_id = "C1234"
    user_id = "U1234"
    user2_id = "U5678"
    return_im = True

    with pytest.raises(ValueError):
        await bot.api.conversations.open(
            channel=channel_id,
            users=[user_id],
        )
    with pytest.raises(ValueError):
        await bot.api.conversations.open()

    await bot.api.conversations.open(
        channel=channel_id,
        return_im=return_im,
    )
    call = bot.call_queue.pop()
    assert call.method == "conversations.open"
    assert call.data == {
        "channel": channel_id,
        "return_im": bool2str(return_im),
    }

    await bot.api.conversations.open(channel=channel_id, )
    call = bot.call_queue.pop()
    assert call.method == "conversations.open"
    assert call.data == {
        "channel": channel_id,
    }

    await bot.api.conversations.open(users=[user_id, user2_id], )
    call = bot.call_queue.pop()
    assert call.method == "conversations.open"
    assert "users" in call.data
    assert set(call.data["users"].split(",")) == {user_id, user2_id}
Exemplo n.º 20
0
def test_bool2str():
    assert bool2str(True) == '1'
    assert bool2str(False) == '0'
Exemplo n.º 21
0
async def test_slack_api_chat_post_message():
    bot = FakeBot()
    channel = bot.add_channel('C4567', 'test')
    channel_id = 'C1234'
    attachments = [Attachment(
        fallback='fallback val',
        title='title val',
        fields=[Field('field title1', 'field value1', False)],
    )]
    text = 'text val'
    parse = 'text'
    username = '******'
    icon_url = (
        'https://item4.github.io/static/images/favicon/apple-icon-57x57.png'
    )
    icon_emoji = ':cake:'
    thread_ts = '12.34'

    bot = FakeBot()

    with pytest.raises(TypeError):
        await bot.api.chat.postMessage(channel=channel)

    await bot.api.chat.postMessage(channel=channel, text=text, as_user=True)

    call = bot.call_queue.pop()
    assert call.method == 'chat.postMessage'
    assert call.data == {
        'channel': channel.id,
        'text': text,
        'as_user': bool2str(True),
    }

    await bot.api.chat.postMessage(channel=channel_id, attachments=attachments)

    call = bot.call_queue.pop()
    assert call.method == 'chat.postMessage'
    assert call.data == {
        'channel': channel_id,
        'attachments': ('[{"fallback":"fallback val","title":"title val",'
                        '"fields":[{"title":"field title1",'
                        '"value":"field value1","short":"0"}]}]'),
    }

    await bot.api.chat.postMessage(
        channel=channel,
        text=text,
        parse=parse,
        link_names=True,
        attachments=attachments,
        unfurl_links=False,
        unfurl_media=True,
        username=username,
        as_user=False,
        icon_url=icon_url,
        icon_emoji=icon_emoji,
        thread_ts=thread_ts,
        reply_broadcast=True,
        response_type='in_channel',
        replace_original=False,
        delete_original=True,
    )

    call = bot.call_queue.pop()
    assert call.method == 'chat.postMessage'
    assert call.data == {
        'channel': channel.id,
        'text': text,
        'parse': parse,
        'link_names': bool2str(True),
        'attachments': ('[{"fallback":"fallback val","title":"title val",'
                        '"fields":[{"title":"field title1",'
                        '"value":"field value1","short":"0"}]}]'),
        'unfurl_links': bool2str(False),
        'unfurl_media': bool2str(True),
        'username': username,
        'as_user': bool2str(False),
        'icon_url': icon_url,
        'icon_emoji': icon_emoji,
        'thread_ts': thread_ts,
        'reply_broadcast': bool2str(True),
        'response_type': 'in_channel',
        'replace_original': bool2str(False),
        'delete_original': bool2str(True),
    }
Exemplo n.º 22
0
def test_bool2str():
    assert bool2str(True) == "1"
    assert bool2str(False) == "0"