aboutsummaryrefslogtreecommitdiff
path: root/tests/test_awaiter.py
blob: 78d25a8e3b0bbc1298fe04f5e82e2c5417faef7d (plain)
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
39
40
from unittest.mock import ANY

from aiounittest import AsyncTestCase
from discord import Object

from drutils.awaiter import AdvancedAwaiter
from .utils import get_mock_coro

TEST_TEXT = "ABCDEF"
TEST_RESPONSE = "DEFABC"
TEST_MESSAGE_ID = 3
TEST_USER_ID = 2
TEST_CHANNEL_ID = 1
TEST_TIMEOUT = 100


class AwaiterTest(AsyncTestCase):

    def setUp(self):
        super().setUp()
        self.ctx = Object(id=0)
        self.bot = Object(id=0)
        self.message = Object(id=TEST_MESSAGE_ID)
        self.message.content = TEST_RESPONSE
        self.user = Object(id=TEST_USER_ID)
        self.message.author = self.user
        self.bot.wait_for = get_mock_coro(self.message)
        self.channel = Object(id=TEST_CHANNEL_ID)
        self.channel.send = get_mock_coro(None)
        self.ctx.bot = self.bot
        self.ctx.channel = self.channel
        self.ctx.guild = None
        self.ctx.author = self.user

    async def test_text(self):
        awaiter = AdvancedAwaiter.from_context(self.ctx, timeout=TEST_TIMEOUT)
        text = await awaiter.text(TEST_TEXT)
        self.assertEqual(text, TEST_RESPONSE)
        self.bot.wait_for.assert_called_once_with('message', check=ANY, timeout=TEST_TIMEOUT)
        self.assertEqual(self.channel.send.call_args[1]['embed'].description, TEST_TEXT)