aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_say.py
blob: 76f1b94734de3f0a3ec2ab4d73d29be1db0cadbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pytest
from unittest.mock import AsyncMock, patch
from cogs.say import Say
from conftest import MockApplicationContext


@pytest.fixture
def say_cog(bot):
    cog = Say(bot)
    return cog


@pytest.mark.asyncio
async def test_say_command(say_cog, mock_channel, mock_guild, bot):
    ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)

    with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send:
        await say_cog.say.callback(say_cog, ctx, "Hello World")
        mock_send.assert_called_once_with(content="Hello World")


@pytest.mark.asyncio
async def test_say_command_empty_text(say_cog, mock_channel, mock_guild, bot):
    ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)

    with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send:
        await say_cog.say.callback(say_cog, ctx, "")
        mock_send.assert_called_once_with(content="")


@pytest.mark.asyncio
async def test_say_command_long_text(say_cog, mock_channel, mock_guild, bot):
    ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild)
    long_text = "A" * 2000

    with patch.object(ctx, 'send', new_callable=AsyncMock) as mock_send:
        await say_cog.say.callback(say_cog, ctx, long_text)
        mock_send.assert_called_once_with(content=long_text)