From 8f4ae4e379d2be54be3d3a9c514d5e4aa342bc00 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 2 Aug 2024 13:24:20 -0400 Subject: [PATCH] refactor: Make the test easier to debug in the future. This test had a redundant call to get the course data from the store because that already happens at the end of the setup function. And also because expected call structure was being built inside the assert, it made it harder to inspect when debugging. Make the code a little bit easire to debug in case we're back here in the future. --- .../grades/tests/integration/test_events.py | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/lms/djangoapps/grades/tests/integration/test_events.py b/lms/djangoapps/grades/tests/integration/test_events.py index 52c1f14bacd8..315ffd65ef25 100644 --- a/lms/djangoapps/grades/tests/integration/test_events.py +++ b/lms/djangoapps/grades/tests/integration/test_events.py @@ -84,40 +84,38 @@ def setUp(self): @patch('lms.djangoapps.grades.events.tracker') def test_submit_answer(self, events_tracker): self.submit_question_answer('p1', {'2_1': 'choice_choice_2'}) - course = self.store.get_course(self.course.id, depth=0) event_transaction_id = events_tracker.emit.mock_calls[0][1][1]['event_transaction_id'] - events_tracker.emit.assert_has_calls( - [ - mock_call( - events.PROBLEM_SUBMITTED_EVENT_TYPE, - { - 'user_id': str(self.student.id), - 'event_transaction_id': event_transaction_id, - 'event_transaction_type': events.PROBLEM_SUBMITTED_EVENT_TYPE, - 'course_id': str(self.course.id), - 'problem_id': str(self.problem.location), - 'weighted_earned': 2.0, - 'weighted_possible': 2.0, - }, - ), - mock_call( - events.COURSE_GRADE_CALCULATED, - { - 'course_version': str(course.course_version), - 'percent_grade': 0.02, - 'grading_policy_hash': 'ChVp0lHGQGCevD0t4njna/C44zQ=', - 'user_id': str(self.student.id), - 'letter_grade': '', - 'event_transaction_id': event_transaction_id, - 'event_transaction_type': events.PROBLEM_SUBMITTED_EVENT_TYPE, - 'course_id': str(self.course.id), - 'course_edited_timestamp': str(course.subtree_edited_on), - } - ), - ], - any_order=True, - ) + expected_calls = [ + mock_call( + events.PROBLEM_SUBMITTED_EVENT_TYPE, + { + 'user_id': str(self.student.id), + 'event_transaction_id': event_transaction_id, + 'event_transaction_type': events.PROBLEM_SUBMITTED_EVENT_TYPE, + 'course_id': str(self.course.id), + 'problem_id': str(self.problem.location), + 'weighted_earned': 2.0, + 'weighted_possible': 2.0, + }, + ), + mock_call( + events.COURSE_GRADE_CALCULATED, + { + 'course_version': str(self.course.course_version), + 'percent_grade': 0.02, + 'grading_policy_hash': 'ChVp0lHGQGCevD0t4njna/C44zQ=', + 'user_id': str(self.student.id), + 'letter_grade': '', + 'event_transaction_id': event_transaction_id, + 'event_transaction_type': events.PROBLEM_SUBMITTED_EVENT_TYPE, + 'course_id': str(self.course.id), + 'course_edited_timestamp': str(self.course.subtree_edited_on), + } + ), + ] + + events_tracker.emit.assert_has_calls(expected_calls, any_order=True) @ddt.data(True, False) def test_delete_student_state(self, emit_signals):