Add ai_responder, some more stuff.
This commit is contained in:
+24
-20
@@ -20,30 +20,34 @@ class TestBotBase(unittest.IsolatedAsyncioTestCase):
|
||||
"temperature": 0.9,
|
||||
}
|
||||
self.history_data = []
|
||||
|
||||
|
||||
class TestFunctionality(TestBotBase):
|
||||
|
||||
def test_load_config(self):
|
||||
with patch('builtins.open', mock_open(read_data=json.dumps(self.config_data))):
|
||||
result = FjerkroaBot.load_config('config.json')
|
||||
self.assertEqual(result, self.config_data)
|
||||
|
||||
async def test_on_message_event(self):
|
||||
with patch.object(FjerkroaBot, 'load_config', new=lambda s, c: self.config_data), \
|
||||
patch.object(FjerkroaBot, 'user', new_callable=PropertyMock) as mock_user:
|
||||
mock_user.return_value = MagicMock(spec=User)
|
||||
mock_user.return_value.id = 12
|
||||
bot = FjerkroaBot('config.json')
|
||||
message = MagicMock(spec=Message)
|
||||
message.content = "Hello, how are you?"
|
||||
message.author = AsyncMock(spec=User)
|
||||
message.author.id = 123
|
||||
message.author.bot = False
|
||||
message.channel = AsyncMock(spec=TextChannel)
|
||||
message.channel.send = AsyncMock()
|
||||
await bot.on_message(message)
|
||||
message.channel.send.assert_called_once_with("Hello!")
|
||||
self.bot = FjerkroaBot('config.json')
|
||||
|
||||
def create_message(self, message: str) -> Message:
|
||||
message = MagicMock(spec=Message)
|
||||
message.content = "Hello, how are you?"
|
||||
message.author = AsyncMock(spec=User)
|
||||
message.author.id = 123
|
||||
message.author.bot = False
|
||||
message.channel = AsyncMock(spec=TextChannel)
|
||||
message.channel.send = AsyncMock()
|
||||
return message
|
||||
|
||||
|
||||
class TestFunctionality(TestBotBase):
|
||||
|
||||
def test_load_config(self) -> None:
|
||||
with patch('builtins.open', mock_open(read_data=json.dumps(self.config_data))):
|
||||
result = FjerkroaBot.load_config('config.json')
|
||||
self.assertEqual(result, self.config_data)
|
||||
|
||||
async def test_on_message_event(self) -> None:
|
||||
message = self.create_message("Hello there! How are you?")
|
||||
await self.bot.on_message(message)
|
||||
message.channel.send.assert_called_once_with("Hello!")
|
||||
|
||||
|
||||
if __name__ == "__mait__":
|
||||
|
||||
Reference in New Issue
Block a user