Exemplo n.º 1
0
 def test_fire_registered_event_cancel(self):
     bot = Bot("app_name", "version")
     on_message = AsyncMock()
     on_message.__name__ = "on_message"
     on_message.return_value = False
     bot.register_event(on_message)
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     message = AsyncMock()
     message.content = "hello there"
     self._await(bot.on_message(message))
     on_message.assert_awaited_once_with(message)
     watcher_callback.assert_not_awaited()
Exemplo n.º 2
0
 def test_no_mention(self):
     bot = Bot("app_name", "version")
     bot.enforce_write_permission = False
     simple_callback = AsyncMock()
     bot.register_command("test", simple_callback, "short", "long")
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     fallback_callback = AsyncMock()
     bot.register_fallback(fallback_callback)
     message = AsyncMock()
     message.content = "hello there"
     self._await(bot.on_message(message))
     simple_callback.assert_not_awaited()
     watcher_callback.assert_awaited_once_with(bot.client, message)
     fallback_callback.assert_not_awaited()
Exemplo n.º 3
0
 def test_mention_self(self):
     bot = Bot("app_name", "version")
     bot.enforce_write_permission = False
     bot.client.user.id = "12345"
     simple_callback = AsyncMock()
     bot.register_command("test", simple_callback, "short", "long")
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     fallback_callback = AsyncMock()
     bot.register_fallback(fallback_callback)
     message = AsyncMock()
     message.content = "<@12345> test arg0 arg1"
     message.author = bot.client.user
     self._await(bot.on_message(message))
     simple_callback.assert_not_awaited()
     watcher_callback.assert_not_awaited()
     fallback_callback.assert_not_awaited()
Exemplo n.º 4
0
 def test_mention_command_regex(self):
     bot = Bot("app_name", "version")
     bot.enforce_write_permission = False
     bot.client.user.id = "12345"
     regex_callback = AsyncMock()
     bot.register_command("^t[eo]a?st$", regex_callback, "short", "long")
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     fallback_callback = AsyncMock()
     bot.register_fallback(fallback_callback)
     message = AsyncMock()
     message.content = "<@12345> toast hey"
     self._await(bot.on_message(message))
     regex_callback.assert_awaited_once_with(bot.client, message, "toast",
                                             "hey")
     watcher_callback.assert_awaited_once_with(bot.client, message)
     fallback_callback.assert_not_awaited()
Exemplo n.º 5
0
 def test_lower_command_names_off(self):
     bot = Bot("app_name", "version")
     bot.enforce_write_permission = False
     bot.lower_command_names = False
     bot.client.user.id = "12345"
     simple_callback = AsyncMock()
     bot.register_command("test", simple_callback, "short", "long")
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     fallback_callback = AsyncMock()
     bot.register_fallback(fallback_callback)
     message = AsyncMock()
     message.content = "<@12345> Test arg0 arg1"
     self._await(bot.on_message(message))
     simple_callback.assert_not_awaited()
     watcher_callback.assert_awaited_once_with(bot.client, message)
     fallback_callback.assert_awaited_once_with(bot.client, message, "Test",
                                                "arg0", "arg1")
Exemplo n.º 6
0
 def test_mention_direct(self):
     bot = Bot("app_name", "version")
     bot.enforce_write_permission = False
     bot.client.user.id = "12345"
     simple_callback = AsyncMock()
     bot.register_command("test", simple_callback, "short", "long")
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     fallback_callback = AsyncMock()
     bot.register_fallback(fallback_callback)
     message = AsyncMock()
     message.content = "<@12345> test arg0 arg1"
     message.channel.type == discord.ChannelType.private
     self._await(bot.on_message(message))
     simple_callback.assert_awaited_once_with(bot.client, message, "test",
                                              "arg0", "arg1")
     watcher_callback.assert_awaited_once_with(bot.client, message)
     fallback_callback.assert_not_awaited()
Exemplo n.º 7
0
 def test_mention_no_permission(self):
     bot = Bot("app_name", "version")
     bot.client.user.id = "12345"
     simple_callback = AsyncMock()
     bot.register_command("test", simple_callback, "short", "long")
     watcher_callback = AsyncMock()
     bot.register_watcher(watcher_callback)
     fallback_callback = AsyncMock()
     bot.register_fallback(fallback_callback)
     message = AsyncMock()
     message.content = "<@12345> test hey"
     message.channel.__repr__ = lambda *a: "test_channel"
     message.guild.__repr__ = lambda *a: "test_guild"
     permissions = AsyncMock()
     permissions.send_messages = False
     message.channel.permissions_for = lambda u: permissions
     self._await(bot.on_message(message))
     simple_callback.assert_not_awaited()
     watcher_callback.assert_awaited_once_with(bot.client, message)
     fallback_callback.assert_not_awaited()
     message.author.create_dm.assert_awaited_once()
     message.author.dm_channel.send.assert_awaited_once_with(
         f"Hi, this bot doesn't have the permission to send a message to"
         f" #test_channel in server 'test_guild'")
Exemplo n.º 8
0
 def test_no_mention_minial(self):
     bot = Bot("app_name", "version")
     message = AsyncMock()
     message.content = "hello there"
     self._await(bot.on_message(message))