diff --git a/src/bot.py b/src/bot.py index 5edc258..3177c8b 100644 --- a/src/bot.py +++ b/src/bot.py @@ -137,6 +137,12 @@ async def on_ready(): office_hours.init(bot) spam.init(bot) #initialize the spam function of the bot so spam.py has # access to the bot and clearing starts + # Initialize ranking system + for x in bot.get_guild(guild_id).members: + # if x.bot is False: bots must have rank in order to do testing + insert_query = f"INSERT INTO rank (user_id) VALUES ({x.id})" + db.mutation_query(insert_query) + print("Ranking system initialized!") print('Logged in as') print(bot.user.name) print(bot.user.id) @@ -178,9 +184,9 @@ async def on_guild_join(guild): await channel.send("To add Instructors, type \"!setInstructor @\"") # Initialize ranking system for x in guild.members: - if x.bot is False: - insert_query = f"INSERT INTO rank (user_id) VALUES ({x.id})" - db.mutation_query(insert_query) + # if x.bot is False: bots must have rank in order to do testing + insert_query = f"INSERT INTO rank (user_id) VALUES ({x.id})" + db.mutation_query(insert_query) print("Ranking system initialized!") await channel.send("Ranking system initialized!") #await channel.send("To remove instructors, type \"!removeInstructor @\"") diff --git a/test/test_ranking.py b/test/test_ranking.py index c9093a3..c16d514 100644 --- a/test/test_ranking.py +++ b/test/test_ranking.py @@ -1,9 +1,9 @@ # ########################### # # Tests Ranking # ########################### -# from time import sleep -# import discord -# from utils import wait_for_msg +from time import sleep +import discord +from utils import wait_for_msg # ########################### # # Function: test @@ -13,11 +13,11 @@ # # - guild_id: id of the guild that is using the TeachersPetBot # # Outputs: None # ########################### -# async def test(testing_bot): -# general_channel = discord.utils.get(testing_bot.get_all_channels(), name='general') -# await test_rank_for_same_user(testing_bot, general_channel) -# await test_rank_for_other_user(testing_bot, general_channel) -# await test_rank_for_other_user_who_does_not_exist(testing_bot, general_channel) +async def test(testing_bot): + general_channel = discord.utils.get(testing_bot.get_all_channels(), name='general') + await test_rank_for_same_user(testing_bot, general_channel) + await test_rank_for_other_user(testing_bot, general_channel) + await test_rank_for_other_user_who_does_not_exist(testing_bot, general_channel) # ########################### @@ -27,27 +27,24 @@ # # - testing_bot: bot that sends commands to test TeachersPetBot # # Outputs: None # ########################### - -# async def test_rank_for_same_user(testing_bot, general_channel): -# print("testing ranking for same user") -# await general_channel.send('!rank') -# print('a') -# response = await testing_bot.wait_for('message', check=lambda x: x.guild.id==general_channel.guild.id and bool(x.attachments)) -# print('b') -# return response - -# async def test_rank_for_other_user(testing_bot, general_channel): -# await general_channel.send('!rank @Clorox-B2') -# response = await testing_bot.wait_for('message', check=lambda x: x.guild.id==general_channel.guild.id and bool(x.attachments)) -# print(response) -# return response - - -# async def test_rank_for_other_user_who_does_not_exist(testing_bot, general_channel): -# await general_channel.send('!rank @Clorox-B3') -# response = await testing_bot.wait_for('message', check=lambda x: x.guild.id==general_channel.guild.id and bool(x.attachments)) -# print(response) -# return response - - - +async def test_rank_for_same_user(testing_bot, general_channel): + print("testing ranking for same user") + await general_channel.send('!rank') + response = await testing_bot.wait_for('message', check=lambda x: x.guild.id==general_channel.guild.id and bool(x.attachments)) + return response + +async def test_rank_for_other_user(testing_bot, general_channel): + for member1 in testing_bot.get_all_members(): + if member1.name == 'cloroxb2': # enter the username of a member + member = member1 + print(member1.name) + await general_channel.send(f'!rank {member.mention}') + response = await testing_bot.wait_for('message', check=lambda x: x.guild.id==general_channel.guild.id and bool(x.attachments)) + print(response) + return response + + +async def test_rank_for_other_user_who_does_not_exist(testing_bot, general_channel): + await general_channel.send('!rank @Clorox-B3') + #response = await testing_bot.wait_for('message', check=lambda x: x.guild.id==general_channel.guild.id and bool(x.attachments)) + await wait_for_msg(testing_bot, general_channel, 'No @Clorox-B3 in the database') diff --git a/test/tests.py b/test/tests.py index acc6e95..7122080 100644 --- a/test/tests.py +++ b/test/tests.py @@ -16,6 +16,7 @@ import test_regrade import test_email_address import test_spam +import test_ranking if platform.system() == 'Windows': asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) @@ -55,6 +56,8 @@ async def run_tests(): #await test_email_utility.test() print('testing spam\n----------') await test_spam.test(testing_bot, TEST_GUILD_ID) + print('testing rank card\n----------') + await test_ranking.test(testing_bot) except AssertionError as ex: print('exception: ', type(ex).__name__ + ':', ex) print('--')