def test_log_read_0(): # case 0, [None, None, None] """Test log read.""" date = "08/11/2019" arg_list = [None, None, None] logs = CommandLog("logs.sample.json") res = logs.log_read(date, *arg_list) # print(res) assert len(res) == 5
def test_log_read_7(): # case 7, [user, command, channel] """Test log read.""" date = "08/11/2019" arg_list = ["bart", "kick", "faq"] logs = CommandLog("logs.sample.json") res = logs.log_read(date, *arg_list) # print(res) ref = ('08/11/2019', '23h07m12s') assert res[0] == ref
def test_log_read_6(): # case 6, [user, command, None] """Test log read.""" date = "08/11/2019" arg_list = ["homer", "ban", None] logs = CommandLog("logs.sample.json") res = logs.log_read(date, *arg_list) # print(res) ref = ('23h07m32s', 'homer', 'general') assert res[0] == ref
def test_log_read_5(): # case 5, [user, None, channel] """Test log read.""" date = "08/11/2019" arg_list = ["lisa", None, "faq"] logs = CommandLog("logs.sample.json") res = logs.log_read(date, *arg_list) # print(res) ref = ('23h07m25s', 'lisa', 'clear') assert res[0] == ref
def test_log_read_3(): # case 0, [None, command, channel] """Test log read.""" date = "08/11/2019" arg_list = [None, "clear", "general"] logs = CommandLog("logs.sample.json") res = logs.log_read(date, *arg_list) # print(res) ref = ('23h07m21s', 'lisa', 'clear') assert res[1] == ref
def test_log_read_1(): # case 1, [None, None, channel] """Test log read.""" date = "08/11/2019" arg_list = [None, None, "faq"] logs = CommandLog("logs.sample.json") res = logs.log_read(date, *arg_list) # print(res) ref = ('23h07m12s', 'bart', 'kick') assert res[0] == ref
async def test_team_success(bot): team_role_name = staff_role[0] # DCT-team dpytest.configure(bot, num_members=2) bot.log = CommandLog("test_log.json") guild = bot.guilds[0] # Guild object team_role = await guild.create_role(name=team_role_name) # Role object bot.role_dcteam = team_role member1 = guild.members[0] # Member member2 = guild.members[1] # Member m2_mention = member2.mention bot.add_cog(Team(bot)) # Before command assert team_role not in member2.roles # m2 doesn't have the role await member1.add_roles(team_role) # m1 has the role Team await dpytest.message(f'!team {m2_mention}') # m1 gives m2 a new role # After assert team_role in member2.roles # m2 has the role dpytest.verify_message("Bienvenue dans la Team !")
async def test_clear_fail(bot): team_role_name = staff_role[0] # DCT-team dpytest.configure(bot) bot.log = CommandLog("test_log.json") # await dpytest.message("message 1") # await dpytest.message("message 2") # await dpytest.message("message 3") # last_message = bot.guilds[0].channels[0].last_message.content # assert last_message == "message 3" guild = bot.guilds[0] # Guild object team_role = await guild.create_role(name=team_role_name) # Role object bot.role_dcteam = team_role member_mention = guild.members[0].mention # Member bot.add_cog(Team(bot)) with pytest.raises(commands.MissingAnyRole): await dpytest.message(f'!clear 2') dpytest.verify_message(f"Tu n'as pas le pouvoir{member_mention} !") await dpytest.empty_queue()
async def test_kick_fail(bot): modo_role_name = mods_role[0] # Moderator guild = bot.guilds[0] # Guild object modo_role = await guild.create_role(name=modo_role_name) # Role object bot.role_modo = modo_role member1 = guild.members[0] # Member member2 = guild.members[1] # Member m1_mention = member1.mention m2_mention = member2.mention bot.log = CommandLog("test_log.json") bot.add_cog(Mod(bot)) with pytest.raises(commands.MissingAnyRole): await dpytest.message(f'!kick {m2_mention}') dpytest.verify_message(f"Tu n'as pas de pouvoirs{m1_mention} !") await dpytest.empty_queue()
async def on_ready(): """Log in Discord.""" print('Logged in as') print(bot.user.name) print(bot.user.id) print('------') bot.guild = bot.get_guild( main_guild_id) # se lier au serveur à partir de l'ID try: bot.role_dcteam = bot.guild.get_role(dcteam_role_id) bot.role_modo = bot.guild.get_role(modo_role_id) except AttributeError: bot.role_dcteam = 0 bot.role_modo = 0 bot.prefix = prefix bot.nsfw_channel = discord.utils.get(bot.guild.text_channels, name='nsfw') # noqa:E501 bot.log = CommandLog("logs.json") bot.gifs = my_giflist for cog in cogs_list: bot.add_cog(cog(bot))
async def test_kick_success(bot): modo_role_name = mods_role[0] # Moderator guild = bot.guilds[0] # Guild object modo_role = await guild.create_role(name=modo_role_name) # Role object bot.role_modo = modo_role member1 = guild.members[0] # Member member2 = guild.members[1] # Member # m1_mention = member1.mention m2_mention = member2.mention bot.log = CommandLog("test_log.json") bot.add_cog(Mod(bot)) await member1.add_roles(modo_role) # m1 has the role Moderator assert len(guild.members) == 3 # member1, member2 and the bot await dpytest.message(f'!kick {m2_mention}') dpytest.verify_message("Adios muchachos !") assert len(guild.members) == 2 # member1 and the bot
async def test_team_fail(bot): team_role_name = staff_role[0] # DCT-team guild = bot.guilds[0] # Guild object team_role = await guild.create_role(name=team_role_name) # Role object bot.role_dcteam = team_role # member1 = guild.members[0] # Member bot.log = CommandLog("test_log.json") bot.add_cog(Team(bot)) member2 = guild.members[1] # Member m2_mention = member2.mention with pytest.raises(commands.MissingAnyRole): await dpytest.message(f'!team {m2_mention}') # m1 gives m2 a new role # After assert team_role not in member2.roles # m2 has NOT the role dpytest.verify_message("Bien tenté mais tu n'as pas de pouvoir ici !")
async def test_team_member_allready_in_team(bot): """Test !team with one member allready in team.""" team_role_name = staff_role[0] # DCT-team dpytest.configure(bot, num_members=3) bot.log = CommandLog("test_log.json") guild = bot.guilds[0] # Guild object team_role = await guild.create_role(name=team_role_name) # Role object bot.role_dcteam = team_role member1 = guild.members[0] # Member member2 = guild.members[1] # Member member3 = guild.members[2] # Member m2_mention = member2.mention m3_mention = member3.mention bot.add_cog(Team(bot)) await member1.add_roles(team_role) # m1 has the role Team await member2.add_roles(team_role) # m2 has the role Team # Before command assert team_role not in member3.roles # m2 doesn't have the role # test empty mentions -> nothing happens await dpytest.message('!team') dpytest.verify_message(assert_nothing=True) await dpytest.message(f'!team {m2_mention} {m3_mention}' ) # m1 gives m2 a new role # After assert team_role in member3.roles # m3 has the role dpytest.verify_message("Bienvenue dans la Team !")
async def test_team_empty_mentions(bot): """Test "team!" command with no mentions.""" team_role_name = staff_role[0] # DCT-team dpytest.configure(bot, num_members=2) bot.log = CommandLog("test_log.json") guild = bot.guilds[0] # Guild object team_role = await guild.create_role(name=team_role_name) # Role object bot.role_dcteam = team_role member1 = guild.members[0] # Member member2 = guild.members[1] # Member bot.add_cog(Team(bot)) # Before command assert team_role not in member2.roles # m2 doesn't have the role await member1.add_roles(team_role) # m1 has the role Team # test empty mentions -> nothing happens await dpytest.message('!team') dpytest.verify_message(assert_nothing=True)