-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
43 lines (30 loc) · 1.2 KB
/
tests.py
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
41
42
43
import unittest
from unittest.mock import AsyncMock, patch
from bot import *
#go through code to test all functions
# event: event_ready()
# event: on_message_handler()
# command: say_hello()
# command: roll_dice()
# command: flip_coin()
# command(sherbotbot)
#commands: sun_sign_command()
#commands: draw_card()
class TestDrawCard(unittest.IsolatedAsyncioTestCase):
async def test_draw_card(self):
# test for expected card
mock_message = AsyncMock()
with patch('bot.random.choice', return_value ='Sherbot drew The Fool'):
await draw_card(mock_message)
mock_message.send.assert_called_once_with('The Fool')
# test for user's name contained in message sent
mock_message = AsyncMock()
mock_message.author.name = "Sherbot"
with patch('bot.random.choice', return_value ='The Magician'):
await draw_card(mock_message)
mock_message.send.assert_called_once_with('Sherbot drew the Magician')
# test that the drawn card is from the tarot deck
mock_message = AsyncMock()
with patch('bot.random.choice', side_effect=Exception('invalid card')):
with self.assertRaises(Exception):
await draw_card(mock_message)