-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16c8103
commit cbf4a07
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import unittest | ||
from unittest.mock import patch, Mock, MagicMock | ||
from apps.discord import Bot # Replace 'Bot' with the name of the file containing your bot's code. | ||
|
||
class TestBot(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.llm_mock = Mock() | ||
self.agent_mock = Mock() | ||
self.bot = Bot(agent=self.agent_mock, llm=self.llm_mock) | ||
|
||
@patch('Bot.load_dotenv') # Mocking the `load_dotenv` function call. | ||
def test_initialization(self, mock_load_dotenv): | ||
self.assertIsNotNone(self.bot.bot) | ||
self.assertEqual(self.bot.agent, self.agent_mock) | ||
self.assertEqual(self.bot.llm, self.llm_mock) | ||
mock_load_dotenv.assert_called_once() | ||
|
||
@patch('Bot.commands.bot') | ||
def test_greet(self, mock_bot): | ||
ctx_mock = Mock() | ||
ctx_mock.author.name = "TestUser" | ||
self.bot.bot.clear() | ||
self.bot.bot.greet(ctx_mock) | ||
ctx_mock.send.assert_called_with("hello, TestUser!") | ||
|
||
# Similarly, you can add tests for other commands. | ||
|
||
@patch('Bot.commands.bot') | ||
def test_help_me(self, mock_bot): | ||
ctx_mock = Mock() | ||
self.bot.bot.clear() | ||
self.bot.bot.help_me(ctx_mock) | ||
# Verify the help text was sent. You can check for a substring to make it shorter. | ||
ctx_mock.send.assert_called() | ||
|
||
@patch('Bot.commands.bot') | ||
def test_on_command_error(self, mock_bot): | ||
ctx_mock = Mock() | ||
error_mock = Mock() | ||
error_mock.__class__.__name__ = "CommandNotFound" | ||
self.bot.bot.clear() | ||
self.bot.bot.on_command_error(ctx_mock, error_mock) | ||
ctx_mock.send.assert_called_with("that command does not exist!") | ||
|
||
def test_add_command(self): | ||
def sample_function(*args): | ||
return "Test Response" | ||
|
||
self.bot.add_command("test_command", sample_function) | ||
# Here, you can further test by triggering the command and checking the response. | ||
|
||
# You can add more tests for other commands and functionalities. | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |