Пример #1
0
async def test_slack_api_chat_delete():
    channel_id = 'C1234'
    channel = PublicChannel(id='C4567')

    ts = '1234.56'
    alternative_token = '1234567890'

    bot = FakeBot()

    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
Пример #2
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),
    }
Пример #3
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),
    }
Пример #4
0
 def add_channel(self, id: str, name: str):
     channel = PublicChannel(id=id, name=name)
     self.channels.append(channel)
     return channel
Пример #5
0
 def add_channel(self, id: str, name: str):
     self.channels.append(PublicChannel(id=id, name=name))
Пример #6
0
async def test_slack_api_chat_post_message():
    channel_id = 'C1234'
    channel = PublicChannel(id='C4567')
    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),
    }