def test_fire_registered_event_cancel(self): bot = Bot("app_name", "version") bot.guild_logs_file = self.LOG_PATH on_guild_remove = AsyncMock() on_guild_remove.__name__ = "on_guild_remove" on_guild_remove.return_value = False bot.register_event(on_guild_remove) guild = AsyncMock() self._await(bot.on_guild_remove(guild)) on_guild_remove.assert_awaited_once_with(guild) self.assertFalse(path.exists(self.LOG_PATH))
def test_log(self): bot = Bot("app_name", "version") bot.guild_logs_file = self.LOG_PATH guild1 = AsyncMock() guild1.id = "id1" guild1.name = "name1" guild2 = AsyncMock() guild2.id = "id2" guild2.name = "name2" d = datetime.now() self._await(bot.on_guild_remove(guild1)) self._await(bot.on_guild_remove(guild2)) self.assertTrue(path.exists(self.LOG_PATH)) with open(self.LOG_PATH, encoding="utf-8", mode="r") as f: self.assertEqual( f"{d:%Y-%m-%d %H:%M} -id1: name1\n" f"{d:%Y-%m-%d %H:%M} -id2: name2\n", f.read(), )