From 499bb4121ee6c5958d691b3be6fb04c40f98d3aa Mon Sep 17 00:00:00 2001 From: Jacob Gerlach Date: Tue, 28 Nov 2023 02:30:40 +0000 Subject: [PATCH] Fixed testsgit status! --- cogs/grades.py | 17 +++++++-------- cogs/groups.py | 2 +- test/test_bot.py | 57 +++++++++++++++++++----------------------------- 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/cogs/grades.py b/cogs/grades.py index 6c1665e9..3d202141 100644 --- a/cogs/grades.py +++ b/cogs/grades.py @@ -776,18 +776,17 @@ async def add_grade_category(self, ctx, categoryname: str, weight: str): if existing: await ctx.author.send("This category has already been added..!!") return - - current_weight_sum = float( - db.query( - """SELECT SUM(category_weight) + + current_weight_sum = db.query( + """SELECT SUM(category_weight) FROM grade_categories WHERE guild_id = %s""", - (ctx.guild.id,), - )[0][0] - ) - if current_weight_sum + categoryweight > 1: + (ctx.guild.id,), + )[0][0] + + if current_weight_sum is not None and float(current_weight_sum) + categoryweight > 1 : await ctx.author.send( - "This category weight would make the total weight less than 1..!!" + "This category weight would make the total weight more than 1..!!" ) return diff --git a/cogs/groups.py b/cogs/groups.py index 6f1dee3e..4a177c37 100644 --- a/cogs/groups.py +++ b/cogs/groups.py @@ -304,7 +304,7 @@ async def join(self, ctx, group_num: int): await member.add_roles(role) await ctx.send( - f"You are now in Group {group_num}! There are now {group_count[0][0] + 1}/ {max_members} members." + f"You are now in Group {group_num}! There are now {group_count[0][0] + 1}/{max_members} members." ) # ------------------------------------------------------------------------------------------------------- diff --git a/test/test_bot.py b/test/test_bot.py index 0096f7ec..8197367b 100644 --- a/test/test_bot.py +++ b/test/test_bot.py @@ -35,18 +35,14 @@ async def test_ping(bot): # Tests cogs/groups.py # --------------------- @pytest.mark.asyncio -async def test_groupJoin(bot): +async def test_groupJoin(bot): # first leave all groups just in case in any await dpytest.message("$leave") dpytest.get_message() # Try to join a group await dpytest.message("$join 99") - assert ( - dpytest.verify() - .message() - .content("You are now in Group 99! There are now 1/6 members.") - ) + assert dpytest.verify().message().content("You are now in Group 99! There are now 1/6 members.") # try to join a different group await dpytest.message("$join 1") @@ -71,9 +67,9 @@ async def test_groupJoin(bot): await dpytest.message("$connect") -# ------------------------------------ -# Tests cogs/groups.py error handling -# ------------------------------------ +# # ------------------------------------ +# # Tests cogs/groups.py error handling +# # ------------------------------------ @pytest.mark.asyncio async def test_groupError(bot): # Try to join a group that doesn't exist @@ -83,7 +79,8 @@ async def test_groupError(bot): dpytest.verify() .message() .content( - "To use the join command, do: $join where 0 <= <= 99 \n ( For example: $join 0 )" + "To use the join command, do: $join " + "where 0 <= <= total groups$ \n ( For example: $join 0 )" ) ) @@ -121,6 +118,12 @@ async def test_assignments(bot): .message() .content("A grading category has been added for: Project with weight: 0.7 ") ) + await dpytest.message("$addgradecategory Test 0.1") + assert ( + dpytest.verify() + .message() + .content("This category weight would make the total weight more than 1..!!") + ) ##Adding Assignments # Test adding a valid assignment with new category await dpytest.message("$addassignment HW1 Homework 30") @@ -302,13 +305,9 @@ async def test_gradesStudent(bot): await dpytest.message("$gradebycategory Homework") assert dpytest.verify().message().content("Grade for Homework: 25.00%") await dpytest.message("$gradeforclass") - assert dpytest.verify().message().content("Grade for class: 7.50%") + assert dpytest.verify().message().content("Grade for class: 25.00%") await dpytest.message("$graderequired Homework 50 30") - assert ( - dpytest.verify() - .message() - .content("Grade on next assignment needed to keep 30% in Homework: 33.00%") - ) + assert dpytest.verify().message().content('Grade on next assignment needed to keep 30% in Homework: 33.00%') await dpytest.message("$graderequiredforclass Homework 50 60") assert ( dpytest.verify() @@ -375,7 +374,8 @@ async def test_gradesStudentError(bot): dpytest.verify() .message() .content( - "To use the gradebycategory command, do: $gradebycategory \n ( For example: $gradebycategory tests )" + "To use the gradebycategory command, do: $gradebycategory \n" + + "( For example: $gradebycategory tests )" ) ) await dpytest.message("$gradebycategory FakeCat") @@ -432,22 +432,13 @@ async def test_gradesInstructor(bot): .message() .content("A grading category has been added for: Exams with weight: 0.7 ") ) - await dpytest.message("$addgradecategory Projects 0.5") - assert ( - dpytest.verify() - .message() - .content("A grading category has been added for: Projects with weight: 0.5 ") - ) - await dpytest.message("$deletegradecategory Projects") - assert dpytest.verify().message().content("Projects category has been deleted ") + await dpytest.message("$deletegradecategory Exams") + assert dpytest.verify().message().content("Exams category has been deleted ") + await dpytest.message("$addgradecategory Exams 0.7") # add back + dpytest.get_message() await dpytest.message("$addassignment Midterm1 Exams 100") - assert ( - dpytest.verify() - .message() - .content( - "A grading assignment has been added for: Midterm1 with points: 100 and category: Exams" - ) - ) + assert dpytest.verify().message().contains().content("A grading assignment has been added for: Midterm1 with points: 100 and category: Exams") + await dpytest.message("$addassignment HW1 Homework 10") assert ( dpytest.verify() @@ -718,8 +709,6 @@ async def test_listreminders(bot): .content("All reminders have been cleared..!!") ) - # Tests cogs/deadline.py - # ------------------------------ # Tests reminders due this week