-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_bot.py
41 lines (31 loc) · 1.84 KB
/
test_bot.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
from discord import Message
from unittest import TestCase
from unittest.mock import AsyncMock
# Your other imports...
class TestBotCommands(TestCase):
# Your other test methods...
async def test_generate_valid_model(self):
ctx = await self.bot.get_context(Message(content='!generate model1 test prompt', channel=AsyncMock()))
await self.bot.invoke(ctx)
# Example assertion: Check if the bot sends a message with an attachment
self.assertTrue(ctx.send.called)
self.assertIsInstance(ctx.send.call_args[1]['file'], discord.File)
async def test_generate_invalid_model(self):
ctx = await self.bot.get_context(Message(content='!generate invalid_model test prompt', channel=AsyncMock()))
await self.bot.invoke(ctx)
# Example assertion: Check if the bot sends a message about an invalid model
self.assertTrue(ctx.send.called)
self.assertIn("Invalid model name", ctx.send.call_args[0][0])
async def test_generate_no_permissions(self):
ctx = await self.bot.get_context(Message(content='!generate model1 test prompt', channel=AsyncMock()))
ctx.author.permissions_for.return_value.send_messages = False
await self.bot.invoke(ctx)
# Example assertion: Check if the bot sends a message about lack of permissions
self.assertTrue(ctx.send.called)
self.assertIn("You do not have permission to send messages", ctx.send.call_args[0][0])
async def test_generate_image_exception(self):
ctx = await self.bot.get_context(Message(content='!generate model1 test prompt', channel=AsyncMock()))
await self.bot.invoke(ctx)
# Example assertion: Check if the bot sends a message about an error
self.assertTrue(ctx.send.called)
self.assertIn("An error occurred while generating the image", ctx.send.call_args[0][0])