Skip to content

Commit

Permalink
Fixing all rank tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiatk67 committed Oct 20, 2023
1 parent e9d3cfb commit 9a38584
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
12 changes: 9 additions & 3 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -178,9 +184,9 @@ async def on_guild_join(guild):
await channel.send("To add Instructors, type \"!setInstructor @<member>\"")
# 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 @<member>\"")
Expand Down
61 changes: 29 additions & 32 deletions test/test_ranking.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)


# ###########################
Expand All @@ -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')
3 changes: 3 additions & 0 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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('--')
Expand Down

0 comments on commit 9a38584

Please sign in to comment.