From 8a2c451439ec8c1b51675f0a1b023dea70f0c2c8 Mon Sep 17 00:00:00 2001 From: usamasadiq Date: Sun, 12 Oct 2025 11:10:36 +0500 Subject: [PATCH 1/3] fix: replace deprecated assertDictContainsSubset() --- .../contentstore/views/tests/test_block.py | 12 +- .../djangoapps/student/tests/test_events.py | 176 +++++++------ .../tests/specs/test_testshib.py | 9 +- .../tests/test_identityserver3.py | 6 +- .../third_party_auth/tests/test_lti.py | 25 +- common/test/utils.py | 9 + .../certificates/tests/test_events.py | 124 ++++----- lms/djangoapps/commerce/tests/test_signals.py | 3 +- .../courseware/tests/test_video_mongo.py | 29 +- .../django_comment_client/base/tests_v2.py | 11 +- .../experiments/tests/test_views.py | 3 +- lms/djangoapps/grades/tests/test_events.py | 100 +++---- .../instructor_task/tests/test_integration.py | 3 +- .../tests/test_tasks_helper.py | 247 +++++++++++------- lms/djangoapps/support/tests/test_views.py | 34 ++- .../content_libraries/tests/test_runtime.py | 41 ++- .../course_groups/tests/test_events.py | 34 +-- .../djangoapps/oauth_dispatch/tests/mixins.py | 3 +- .../oauth_dispatch/tests/test_api.py | 8 +- .../oauth_dispatch/tests/test_jwt.py | 3 +- .../user_authn/views/tests/test_auto_auth.py | 6 +- .../user_authn/views/tests/test_events.py | 43 +-- .../user_authn/views/tests/test_login.py | 3 +- .../user_authn/views/tests/test_logout.py | 21 +- .../enterprise_support/tests/test_logout.py | 3 +- .../tests/test_mixed_modulestore.py | 32 ++- 26 files changed, 562 insertions(+), 426 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index 01aff3d613..e01263259b 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -86,6 +86,7 @@ from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import ( add_container_page_publishing_info, create_xblock_info, ) +from common.test.utils import assert_dict_contains_subset class AsideTest(XBlockAside): @@ -863,15 +864,16 @@ class TestDuplicateItem(ItemTest, DuplicateHelper, OpenEdxEventsTestMixin): XBLOCK_DUPLICATED.connect(event_receiver) usage_key = self._duplicate_and_verify(self.vert_usage_key, self.seq_usage_key) event_receiver.assert_called() - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": XBLOCK_DUPLICATED, "sender": None, "xblock_info": DuplicatedXBlockData( - usage_key=usage_key, - block_type=usage_key.block_type, - source_usage_key=self.vert_usage_key, - ), + usage_key=usage_key, + block_type=usage_key.block_type, + source_usage_key=self.vert_usage_key, + ), }, event_receiver.call_args.kwargs, ) diff --git a/common/djangoapps/student/tests/test_events.py b/common/djangoapps/student/tests/test_events.py index f336396e6e..9d57c8ca85 100644 --- a/common/djangoapps/student/tests/test_events.py +++ b/common/djangoapps/student/tests/test_events.py @@ -36,6 +36,7 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.modulestore.tests.django_utils import \ SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order +from common.test.utils import assert_dict_contains_subset class TestUserProfileEvents(UserSettingsEventTestMixin, TestCase): @@ -271,30 +272,31 @@ class EnrollmentEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): enrollment = CourseEnrollment.enroll(self.user, self.course.id) self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": COURSE_ENROLLMENT_CREATED, "sender": None, "enrollment": CourseEnrollmentData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.profile.name, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CourseData( - course_key=self.course.id, - display_name=self.course.display_name, - ), - mode=enrollment.mode, - is_active=enrollment.is_active, - creation_date=enrollment.created, - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.profile.name, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CourseData( + course_key=self.course.id, + display_name=self.course.display_name, + ), + mode=enrollment.mode, + is_active=enrollment.is_active, + creation_date=enrollment.created, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) def test_enrollment_changed_event_emitted(self): @@ -314,30 +316,31 @@ class EnrollmentEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): enrollment.update_enrollment(mode="verified") self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": COURSE_ENROLLMENT_CHANGED, "sender": None, "enrollment": CourseEnrollmentData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.profile.name, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CourseData( - course_key=self.course.id, - display_name=self.course.display_name, - ), - mode=enrollment.mode, - is_active=enrollment.is_active, - creation_date=enrollment.created, - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.profile.name, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CourseData( + course_key=self.course.id, + display_name=self.course.display_name, + ), + mode=enrollment.mode, + is_active=enrollment.is_active, + creation_date=enrollment.created, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) def test_unenrollment_completed_event_emitted(self): @@ -357,30 +360,31 @@ class EnrollmentEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): CourseEnrollment.unenroll(self.user, self.course.id) self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": COURSE_UNENROLLMENT_COMPLETED, "sender": None, "enrollment": CourseEnrollmentData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.profile.name, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CourseData( - course_key=self.course.id, - display_name=self.course.display_name, - ), - mode=enrollment.mode, - is_active=False, - creation_date=enrollment.created, - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.profile.name, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CourseData( + course_key=self.course.id, + display_name=self.course.display_name, + ), + mode=enrollment.mode, + is_active=False, + creation_date=enrollment.created, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) @@ -430,25 +434,26 @@ class TestCourseAccessRoleEvents(TestCase, OpenEdxEventsTestMixin): role.add_users(self.user) self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": COURSE_ACCESS_ROLE_ADDED, "sender": None, "course_access_role_data": CourseAccessRoleData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course_key=self.course_key, - org_key=self.course_key.org, - role=role._role_name, # pylint: disable=protected-access - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course_key=self.course_key, + org_key=self.course_key.org, + role=role._role_name, # pylint: disable=protected-access + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) @ddt.data( @@ -468,23 +473,24 @@ class TestCourseAccessRoleEvents(TestCase, OpenEdxEventsTestMixin): role.remove_users(self.user) self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": COURSE_ACCESS_ROLE_REMOVED, "sender": None, "course_access_role_data": CourseAccessRoleData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course_key=self.course_key, - org_key=self.course_key.org, - role=role._role_name, # pylint: disable=protected-access - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course_key=self.course_key, + org_key=self.course_key.org, + role=role._role_name, # pylint: disable=protected-access + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) diff --git a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py index caddd325ba..18059ac687 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py @@ -30,6 +30,7 @@ from openedx.core.djangoapps.user_authn.views.login import login_user from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerFactory from .base import IntegrationTestMixin +from common.test.utils import assert_dict_contains_subset TESTSHIB_ENTITY_ID = "https://idp.testshib.org/idp/shibboleth" TESTSHIB_METADATA_URL = "https://mock.testshib.org/metadata/testshib-providers.xml" @@ -402,8 +403,10 @@ class TestShibIntegrationTest(SamlIntegrationTestUtilities, IntegrationTestMixin assert msg.startswith("SAML login %s") assert action_type == "request" assert idp_name == self.PROVIDER_IDP_SLUG - self.assertDictContainsSubset( - {"idp": idp_name, "auth_entry": "login", "next": expected_next_url}, request_data + assert_dict_contains_subset( + self, + {"idp": idp_name, "auth_entry": "login", "next": expected_next_url}, + request_data, ) assert next_url == expected_next_url assert " Section > Subsection > Problem1', - 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', - 'title': 'Problem1', - }, student_data[0]) + assert_dict_contains_subset( + self, + { + 'username': 'student', + 'location': 'test_course > Section > Subsection > Problem1', + 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', + 'title': 'Problem1', + }, + student_data[0], + ) assert 'state' in student_data[0] assert student_data_keys_list == ['username', 'title', 'location', 'block_key', 'state'] mock_list_problem_responses.assert_called_with(self.course.id, ANY, ANY) @@ -569,22 +576,30 @@ class TestProblemResponsesReport(TestReportMixin, InstructorTaskModuleTestCase): usage_key_str_list=[str(self.course.location)], ) assert len(student_data) == 2 - self.assertDictContainsSubset({ - 'username': 'student', - 'location': 'test_course > Section > Subsection > Problem1', - 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', - 'title': 'Problem1', - 'some': 'state1', - 'more': 'state1!', - }, student_data[0]) - self.assertDictContainsSubset({ - 'username': 'student', - 'location': 'test_course > Section > Subsection > Problem1', - 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', - 'title': 'Problem1', - 'some': 'state2', - 'more': 'state2!', - }, student_data[1]) + assert_dict_contains_subset( + self, + { + 'username': 'student', + 'location': 'test_course > Section > Subsection > Problem1', + 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', + 'title': 'Problem1', + 'some': 'state1', + 'more': 'state1!', + }, + student_data[0], + ) + assert_dict_contains_subset( + self, + { + 'username': 'student', + 'location': 'test_course > Section > Subsection > Problem1', + 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', + 'title': 'Problem1', + 'some': 'state2', + 'more': 'state2!', + }, + student_data[1], + ) assert student_data[0]['state'] == student_data[1]['state'] assert student_data_keys_list == ['username', 'title', 'location', 'more', 'some', 'block_key', 'state'] @@ -610,22 +625,30 @@ class TestProblemResponsesReport(TestReportMixin, InstructorTaskModuleTestCase): usage_key_str_list=[str(self.course.location)], ) assert len(student_data) == 2 - self.assertDictContainsSubset({ - 'username': 'student', - 'location': 'test_course > Section > Subsection > Problem1', - 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', - 'title': 'Problem1', - 'some': 'state1', - 'more': 'state1!', - }, student_data[0]) - self.assertDictContainsSubset({ - 'username': 'student', - 'location': 'test_course > Section > Subsection > Problem1', - 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', - 'title': 'Problem1', - 'some': 'state2', - 'more': 'state2!', - }, student_data[1]) + assert_dict_contains_subset( + self, + { + 'username': 'student', + 'location': 'test_course > Section > Subsection > Problem1', + 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', + 'title': 'Problem1', + 'some': 'state1', + 'more': 'state1!', + }, + student_data[0], + ) + assert_dict_contains_subset( + self, + { + 'username': 'student', + 'location': 'test_course > Section > Subsection > Problem1', + 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', + 'title': 'Problem1', + 'some': 'state2', + 'more': 'state2!', + }, + student_data[1], + ) assert student_data[0]['state'] == student_data[1]['state'] assert student_data_keys_list == ['username', 'title', 'location', 'some', 'more', 'block_key', 'state'] @@ -642,16 +665,20 @@ class TestProblemResponsesReport(TestReportMixin, InstructorTaskModuleTestCase): usage_key_str_list=[str(self.course.location)], ) assert len(student_data) == 1 - self.assertDictContainsSubset({ - 'username': 'student', - 'location': 'test_course > Section > Subsection > Problem1', - 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', - 'title': 'Problem1', - 'Answer ID': 'Problem1_2_1', - 'Answer': 'Option 1', - 'Correct Answer': 'Option 1', - 'Question': 'The correct answer is Option 1', - }, student_data[0]) + assert_dict_contains_subset( + self, + { + 'username': 'student', + 'location': 'test_course > Section > Subsection > Problem1', + 'block_key': 'block-v1:edx+1.23x+test_course+type@problem+block@Problem1', + 'title': 'Problem1', + 'Answer ID': 'Problem1_2_1', + 'Answer': 'Option 1', + 'Correct Answer': 'Option 1', + 'Question': 'The correct answer is Option 1', + }, + student_data[0], + ) assert 'state' in student_data[0] assert student_data_keys_list == ['username', 'title', 'location', 'Answer', 'Answer ID', 'Correct Answer', 'Question', 'block_key', 'state'] @@ -671,16 +698,20 @@ class TestProblemResponsesReport(TestReportMixin, InstructorTaskModuleTestCase): ) assert len(student_data) == 2 for idx in range(1, 3): - self.assertDictContainsSubset({ - 'username': 'student', - 'location': f'test_course > Section > Subsection > Problem{idx}', - 'block_key': f'block-v1:edx+1.23x+test_course+type@problem+block@Problem{idx}', - 'title': f'Problem{idx}', - 'Answer ID': f'Problem{idx}_2_1', - 'Answer': 'Option 1', - 'Correct Answer': 'Option 1', - 'Question': 'The correct answer is Option 1', - }, student_data[idx - 1]) + assert_dict_contains_subset( + self, + { + 'username': 'student', + 'location': f'test_course > Section > Subsection > Problem{idx}', + 'block_key': f'block-v1:edx+1.23x+test_course+type@problem+block@Problem{idx}', + 'title': f'Problem{idx}', + 'Answer ID': f'Problem{idx}_2_1', + 'Answer': 'Option 1', + 'Correct Answer': 'Option 1', + 'Question': 'The correct answer is Option 1', + }, + student_data[idx - 1], + ) assert 'state' in student_data[(idx - 1)] @ddt.data( @@ -819,7 +850,7 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): """ with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset({'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv([ dict(list(zip( self.csv_header_row, @@ -845,7 +876,7 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): self.submit_student_answer(self.student_1.username, 'Problem1', ['Option 1']) with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset({'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) problem_name = 'Homework 1: Subsection - Problem1' header_row = self.csv_header_row + [problem_name + ' (Earned)', problem_name + ' (Possible)'] self.verify_rows_in_csv([ @@ -891,8 +922,10 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): self.submit_student_answer(student_verified.username, 'Problem1', ['Option 1']) with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset( - {'action_name': 'graded', 'attempted': 1, 'succeeded': 1, 'failed': 0}, result + assert_dict_contains_subset( + self, + {'action_name': 'graded', 'attempted': 1, 'succeeded': 1, 'failed': 0}, + result, ) @patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') @@ -913,7 +946,7 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): self.submit_student_answer(self.student_1.username, 'Problem1', ['Option 1']) with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset({'action_name': 'graded', 'attempted': 3, 'succeeded': 3, 'failed': 0}, result) + assert_dict_contains_subset(self, {'action_name': 'graded', 'attempted': 3, 'succeeded': 3, 'failed': 0}, result) problem_name = 'Homework 1: Subsection - Problem1' header_row = self.csv_header_row + [problem_name + ' (Earned)', problem_name + ' (Possible)'] self.verify_rows_in_csv([ @@ -987,8 +1020,10 @@ class TestProblemReportSplitTestContent(TestReportMixin, TestConditionalContent, with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'): with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset( - {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result + assert_dict_contains_subset( + self, + {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, + result, ) problem_names = ['Homework 1: Subsection - problem_a_url', 'Homework 1: Subsection - problem_b_url'] @@ -1143,8 +1178,10 @@ class TestProblemReportCohortedContent(TestReportMixin, ContentGroupTestCase, In with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'): with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset( - {'action_name': 'graded', 'attempted': 5, 'succeeded': 5, 'failed': 0}, result + assert_dict_contains_subset( + self, + {'action_name': 'graded', 'attempted': 5, 'succeeded': 5, 'failed': 0}, + result, ) problem_names = ['Homework 1: Subsection - Problem0', 'Homework 1: Subsection - Problem1'] header_row = ['Student ID', 'Email', 'Username', 'Enrollment Status', 'Grade'] @@ -1228,7 +1265,7 @@ class TestCourseSurveyReport(TestReportMixin, InstructorTaskCourseTestCase): None, None, self.course.id, task_input, 'generating course survey report' ) - self.assertDictContainsSubset({'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'attempted': 2, 'succeeded': 2, 'failed': 0}, result) def test_generate_course_survey_report(self): """ @@ -1262,7 +1299,7 @@ class TestCourseSurveyReport(TestReportMixin, InstructorTaskCourseTestCase): ]) expected_data = [header_row, student1_row, student2_row] - self.assertDictContainsSubset({'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self._verify_csv_file_report(report_store, expected_data) def _verify_csv_file_report(self, report_store, expected_data): @@ -1297,7 +1334,7 @@ class TestStudentReport(TestReportMixin, InstructorTaskCourseTestCase): links = report_store.links_for(self.course.id) assert len(links) == 1 - self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result) + assert_dict_contains_subset(self, {'attempted': 1, 'succeeded': 1, 'failed': 0}, result) def test_custom_directory(self): self.create_student('student', 'student@example.com') @@ -1352,7 +1389,7 @@ class TestStudentReport(TestReportMixin, InstructorTaskCourseTestCase): result = upload_students_csv(None, None, self.course.id, task_input, 'calculated') # This assertion simply confirms that the generation completed with no errors num_students = len(students) - self.assertDictContainsSubset({'attempted': num_students, 'succeeded': num_students, 'failed': 0}, result) + assert_dict_contains_subset(self, {'attempted': num_students, 'succeeded': num_students, 'failed': 0}, result) class TestTeamStudentReport(TestReportMixin, InstructorTaskCourseTestCase): @@ -1382,7 +1419,7 @@ class TestTeamStudentReport(TestReportMixin, InstructorTaskCourseTestCase): with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task') as mock_current_task: mock_current_task.return_value = current_task result = upload_students_csv(None, None, self.course.id, task_input, 'calculated') - self.assertDictContainsSubset({'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'attempted': 2, 'succeeded': 2, 'failed': 0}, result) report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD') report_csv_filename = report_store.links_for(self.course.id)[0][0] report_path = report_store.path_to(self.course.id, report_csv_filename) @@ -1447,7 +1484,7 @@ class TestListMayEnroll(TestReportMixin, InstructorTaskCourseTestCase): links = report_store.links_for(self.course.id) assert len(links) == 1 - self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result) + assert_dict_contains_subset(self, {'attempted': 1, 'succeeded': 1, 'failed': 0}, result) def test_unicode_email_addresses(self): """ @@ -1463,7 +1500,7 @@ class TestListMayEnroll(TestReportMixin, InstructorTaskCourseTestCase): result = upload_may_enroll_csv(None, None, self.course.id, task_input, 'calculated') # This assertion simply confirms that the generation completed with no errors num_enrollments = len(enrollments) - self.assertDictContainsSubset({'attempted': num_enrollments, 'succeeded': num_enrollments, 'failed': 0}, result) + assert_dict_contains_subset(self, {'attempted': num_enrollments, 'succeeded': num_enrollments, 'failed': 0}, result) class MockDefaultStorage: @@ -1510,7 +1547,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,,Cohort 1\n' 'student_2,,Cohort 2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '1', '', '', '']))), @@ -1525,7 +1562,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): ',student_1@example.com,Cohort 1\n' ',student_2@example.com,Cohort 2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '1', '', '', '']))), @@ -1540,7 +1577,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,student_1@example.com,Cohort 1\n' 'student_2,student_2@example.com,Cohort 2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '1', '', '', '']))), @@ -1561,7 +1598,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,student_1@example.com,Cohort 1\n' # valid username and email 'Invalid,student_2@example.com,Cohort 2' # invalid username, valid email ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '1', '', '', '']))), @@ -1575,7 +1612,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'username,email,cohort\n' 'Invalid,,Cohort 1\n' ) - self.assertDictContainsSubset({'total': 1, 'attempted': 1, 'succeeded': 0, 'failed': 1}, result) + assert_dict_contains_subset(self, {'total': 1, 'attempted': 1, 'succeeded': 0, 'failed': 1}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '0', 'Invalid', '', '']))), @@ -1589,7 +1626,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): ',student_1@example.com,Does Not Exist\n' 'student_2,,Cohort 2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 1, 'failed': 1}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 1, 'failed': 1}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Does Not Exist', 'False', '0', '', '', '']))), @@ -1603,8 +1640,11 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'username,email,cohort\n' ',example_email@example.com,Cohort 1' ) - self.assertDictContainsSubset({'total': 1, 'attempted': 1, 'succeeded': 0, 'failed': 0}, - result) + assert_dict_contains_subset( + self, + {'total': 1, 'attempted': 1, 'succeeded': 0, 'failed': 0}, + result, + ) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '0', '', '', 'example_email@example.com']))), @@ -1617,7 +1657,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'username,email,cohort\n' ',student_1@,Cohort 1\n' ) - self.assertDictContainsSubset({'total': 1, 'attempted': 1, 'succeeded': 0, 'failed': 1}, result) + assert_dict_contains_subset(self, {'total': 1, 'attempted': 1, 'succeeded': 0, 'failed': 1}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '0', '', 'student_1@', '']))), @@ -1642,7 +1682,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,\n' 'student_2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 0, 'failed': 2}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 0, 'failed': 2}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['', 'False', '0', '', '', '']))), @@ -1654,7 +1694,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): result = self._cohort_students_and_upload( 'username,email,cohort' ) - self.assertDictContainsSubset({'total': 0, 'attempted': 0, 'succeeded': 0, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 0, 'attempted': 0, 'succeeded': 0, 'failed': 0}, result) self.verify_rows_in_csv([]) def test_carriage_return(self): @@ -1666,7 +1706,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,,Cohort 1\r' 'student_2,,Cohort 2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '1', '', '', '']))), @@ -1684,7 +1724,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,,Cohort 1\r\n' 'student_2,,Cohort 2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '1', '', '', '']))), @@ -1704,7 +1744,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,,Cohort 2\n' 'student_2,,Cohort 1' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '1', '', '', '']))), @@ -1724,7 +1764,7 @@ class TestCohortStudents(TestReportMixin, InstructorTaskCourseTestCase): 'student_1\xec,,Cohort 1\n' 'student_2,,Cohort 2' ) - self.assertDictContainsSubset({'total': 2, 'attempted': 2, 'skipped': 2, 'failed': 0}, result) + assert_dict_contains_subset(self, {'total': 2, 'attempted': 2, 'skipped': 2, 'failed': 0}, result) self.verify_rows_in_csv( [ dict(list(zip(self.csv_header_row, ['Cohort 1', 'True', '0', '', '', '']))), @@ -1809,7 +1849,8 @@ class TestGradeReport(TestReportMixin, InstructorTaskModuleTestCase): with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'): result = CourseGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, {'action_name': 'graded', 'attempted': 1, 'succeeded': 1, 'failed': 0}, result, ) @@ -1868,7 +1909,8 @@ class TestGradeReport(TestReportMixin, InstructorTaskModuleTestCase): with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'): result = CourseGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, {'action_name': 'graded', 'attempted': 1, 'succeeded': 1, 'failed': 0}, result, ) @@ -1912,8 +1954,10 @@ class TestGradeReport(TestReportMixin, InstructorTaskModuleTestCase): self.submit_student_answer(student_1.username, 'Problem4', ['Option 1']) self.submit_student_answer(student_verified.username, 'Problem4', ['Option 1']) result = CourseGradeReport.generate(None, None, self.course.id, {}, 'graded') - self.assertDictContainsSubset( - {'action_name': 'graded', 'attempted': 1, 'succeeded': 1, 'failed': 0}, result + assert_dict_contains_subset( + self, + {'action_name': 'graded', 'attempted': 1, 'succeeded': 1, 'failed': 0}, + result, ) @ddt.data(True, False) @@ -2517,9 +2561,10 @@ class TestCertificateGeneration(InstructorTaskModuleTestCase): None, None, self.course.id, task_input, 'certificates generated' ) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, expected_results, - result + result, ) def _create_students(self, number_of_students): diff --git a/lms/djangoapps/support/tests/test_views.py b/lms/djangoapps/support/tests/test_views.py index 4abc4508ea..df713daf0b 100644 --- a/lms/djangoapps/support/tests/test_views.py +++ b/lms/djangoapps/support/tests/test_views.py @@ -52,7 +52,7 @@ from common.djangoapps.student.tests.factories import ( UserFactory, ) from common.djangoapps.third_party_auth.tests.factories import SAMLProviderConfigFactory -from common.test.utils import disable_signal +from common.test.utils import disable_signal, assert_dict_contains_subset from lms.djangoapps.program_enrollments.tests.factories import ProgramCourseEnrollmentFactory, ProgramEnrollmentFactory from lms.djangoapps.support.models import CourseResetAudit from lms.djangoapps.support.serializers import ProgramEnrollmentSerializer @@ -343,14 +343,18 @@ class SupportViewEnrollmentsTests(SharedModuleStoreTestCase, SupportViewTestCase assert response.status_code == 200 data = json.loads(response.content.decode('utf-8')) assert len(data) == 1 - self.assertDictContainsSubset({ - 'mode': CourseMode.AUDIT, - 'manual_enrollment': {}, - 'user': self.student.username, - 'course_id': str(self.course.id), - 'is_active': True, - 'verified_upgrade_deadline': None, - }, data[0]) + assert_dict_contains_subset( + self, + { + 'mode': CourseMode.AUDIT, + 'manual_enrollment': {}, + 'user': self.student.username, + 'course_id': str(self.course.id), + 'is_active': True, + 'verified_upgrade_deadline': None, + }, + data[0], + ) assert {CourseMode.VERIFIED, CourseMode.AUDIT, CourseMode.HONOR, CourseMode.NO_ID_PROFESSIONAL_MODE, CourseMode.PROFESSIONAL, CourseMode.CREDIT_MODE} == {mode['slug'] for mode in data[0]['course_modes']} assert 'enterprise_course_enrollments' not in data[0] @@ -471,10 +475,14 @@ class SupportViewEnrollmentsTests(SharedModuleStoreTestCase, SupportViewTestCase ) response = self.client.get(self.url) assert response.status_code == 200 - self.assertDictContainsSubset({ - 'enrolled_by': self.user.email, - 'reason': 'Financial Assistance', - }, json.loads(response.content.decode('utf-8'))[0]['manual_enrollment']) + assert_dict_contains_subset( + self, + { + 'enrolled_by': self.user.email, + 'reason': 'Financial Assistance', + }, + json.loads(response.content.decode('utf-8'))[0]['manual_enrollment'], + ) @disable_signal(signals, 'post_save') @ddt.data('username', 'email') diff --git a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py index 9cb10e514a..97699dbf8d 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py @@ -27,6 +27,7 @@ from openedx.core.djangoapps.xblock import api as xblock_api from openedx.core.djangolib.testing.utils import skip_unless_lms, skip_unless_cms from openedx.core.lib.xblock_serializer import api as serializer_api from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset class ContentLibraryContentTestMixin: @@ -205,10 +206,14 @@ class ContentLibraryRuntimeTests(ContentLibraryContentTestMixin, TestCase): assert metadata_view_result.data['display_name'] == 'New Multi Choice Question' assert 'children' not in metadata_view_result.data assert 'editable_children' not in metadata_view_result.data - self.assertDictContainsSubset({ - "content_type": "CAPA", - "problem_types": ["multiplechoiceresponse"], - }, metadata_view_result.data["index_dictionary"]) + assert_dict_contains_subset( + self, + { + "content_type": "CAPA", + "problem_types": ["multiplechoiceresponse"], + }, + metadata_view_result.data["index_dictionary"], + ) assert metadata_view_result.data['student_view_data'] is None # Capa doesn't provide student_view_data @@ -493,11 +498,15 @@ class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase submit_result = client.post(problem_check_url, data={problem_key: "choice_3"}) assert submit_result.status_code == 200 submit_data = json.loads(submit_result.content.decode('utf-8')) - self.assertDictContainsSubset({ - "current_score": 0, - "total_possible": 1, - "attempts_used": 1, - }, submit_data) + assert_dict_contains_subset( + self, + { + "current_score": 0, + "total_possible": 1, + "attempts_used": 1, + }, + submit_data, + ) # Now test that the score is also persisted in StudentModule: # If we add a REST API to get an individual block's score, that should be checked instead of StudentModule. @@ -509,11 +518,15 @@ class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase submit_result = client.post(problem_check_url, data={problem_key: "choice_1"}) assert submit_result.status_code == 200 submit_data = json.loads(submit_result.content.decode('utf-8')) - self.assertDictContainsSubset({ - "current_score": 1, - "total_possible": 1, - "attempts_used": 2, - }, submit_data) + assert_dict_contains_subset( + self, + { + "current_score": 1, + "total_possible": 1, + "attempts_used": 2, + }, + submit_data, + ) # Now test that the score is also updated in StudentModule: # If we add a REST API to get an individual block's score, that should be checked instead of StudentModule. sm = get_score(self.student_a, block_id) diff --git a/openedx/core/djangoapps/course_groups/tests/test_events.py b/openedx/core/djangoapps/course_groups/tests/test_events.py index 616a7bb3f1..40a04dea8c 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_events.py +++ b/openedx/core/djangoapps/course_groups/tests/test_events.py @@ -18,6 +18,7 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from common.test.utils import assert_dict_contains_subset @skip_unless_lms @@ -90,25 +91,26 @@ class CohortEventTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): ) self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": COHORT_MEMBERSHIP_CHANGED, "sender": None, "cohort": CohortData( - user=UserData( - pii=UserPersonalData( - username=cohort_membership.user.username, - email=cohort_membership.user.email, - name=cohort_membership.user.profile.name, - ), - id=cohort_membership.user.id, - is_active=cohort_membership.user.is_active, - ), - course=CourseData( - course_key=cohort_membership.course_id, - ), - name=cohort_membership.course_user_group.name, - ), + user=UserData( + pii=UserPersonalData( + username=cohort_membership.user.username, + email=cohort_membership.user.email, + name=cohort_membership.user.profile.name, + ), + id=cohort_membership.user.id, + is_active=cohort_membership.user.is_active, + ), + course=CourseData( + course_key=cohort_membership.course_id, + ), + name=cohort_membership.course_user_group.name, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py b/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py index d99ac4883b..407a9aac2b 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/mixins.py @@ -11,6 +11,7 @@ from edx_rest_framework_extensions.auth.jwt.decoder import ( from jwt.exceptions import ExpiredSignatureError from common.djangoapps.student.models import UserProfile, anonymous_id_for_user +from common.test.utils import assert_dict_contains_subset class AccessTokenMixin: @@ -88,7 +89,7 @@ class AccessTokenMixin: expected['grant_type'] = grant_type or '' - self.assertDictContainsSubset(expected, payload) + assert_dict_contains_subset(self, expected, payload) if expires_in: assert payload['exp'] == payload['iat'] + expires_in diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py index 3c064cc63c..5bf1f524bc 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_api.py @@ -9,6 +9,7 @@ from django.test import TestCase from oauth2_provider.models import AccessToken from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset OAUTH_PROVIDER_ENABLED = settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER') if OAUTH_PROVIDER_ENABLED: @@ -43,7 +44,8 @@ class TestOAuthDispatchAPI(TestCase): token = api.create_dot_access_token(HttpRequest(), self.user, self.client) assert token['access_token'] assert token['refresh_token'] - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { 'token_type': 'Bearer', 'expires_in': EXPECTED_DEFAULT_EXPIRES_IN, @@ -63,5 +65,5 @@ class TestOAuthDispatchAPI(TestCase): token = api.create_dot_access_token( HttpRequest(), self.user, self.client, expires_in=expires_in, scopes=['profile'], ) - self.assertDictContainsSubset({'scope': 'profile'}, token) - self.assertDictContainsSubset({'expires_in': expires_in}, token) + assert_dict_contains_subset(self, {'scope': 'profile'}, token) + assert_dict_contains_subset(self, {'expires_in': expires_in}, token) diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py index da95fd072d..647da14f6e 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_jwt.py @@ -12,6 +12,7 @@ from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter from openedx.core.djangoapps.oauth_dispatch.models import RestrictedApplication from openedx.core.djangoapps.oauth_dispatch.tests.mixins import AccessTokenMixin from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset @ddt.ddt @@ -171,7 +172,7 @@ class TestCreateJWTs(AccessTokenMixin, TestCase): token_payload = self.assert_valid_jwt_access_token( jwt_token, self.user, self.default_scopes, aud=aud, secret=secret, ) - self.assertDictContainsSubset(additional_claims, token_payload) + assert_dict_contains_subset(self, additional_claims, token_payload) assert user_email_verified == token_payload['email_verified'] assert token_payload['roles'] == mock_create_roles.return_value diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py index 0346aee25a..b687749030 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py @@ -21,6 +21,7 @@ from openedx.core.djangoapps.django_comment_common.models import ( ) from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order +from common.test.utils import assert_dict_contains_subset class AutoAuthTestCase(UrlResetMixin, TestCase): @@ -182,12 +183,13 @@ class AutoAuthEnabledTestCase(AutoAuthTestCase, ModuleStoreTestCase): for key in ['created_status', 'username', 'email', 'password', 'user_id', 'anonymous_id']: assert key in response_data user = User.objects.get(username=response_data['username']) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { 'created_status': 'Logged in', 'anonymous_id': anonymous_id_for_user(user, None), }, - response_data + response_data, ) @ddt.data(*COURSE_IDS_DDT) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_events.py b/openedx/core/djangoapps/user_authn/views/tests/test_events.py index acec4a935d..4460e8c627 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_events.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_events.py @@ -18,6 +18,7 @@ from openedx_events.tests.utils import OpenEdxEventsTestMixin from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory from openedx.core.djangoapps.user_api.tests.test_views import UserAPITestCase from openedx.core.djangolib.testing.utils import skip_unless_lms +from common.test.utils import assert_dict_contains_subset @skip_unless_lms @@ -83,21 +84,22 @@ class RegistrationEventTest(UserAPITestCase, OpenEdxEventsTestMixin): user = User.objects.get(username=self.user_info.get("username")) self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": STUDENT_REGISTRATION_COMPLETED, "sender": None, "user": UserData( - pii=UserPersonalData( - username=user.username, - email=user.email, - name=user.profile.name, - ), - id=user.id, - is_active=user.is_active, - ), + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.profile.name, + ), + id=user.id, + is_active=user.is_active, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) @@ -165,19 +167,20 @@ class LoginSessionEventTest(UserAPITestCase, OpenEdxEventsTestMixin): user = User.objects.get(username=self.user.username) self.assertTrue(self.receiver_called) - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": SESSION_LOGIN_COMPLETED, "sender": None, "user": UserData( - pii=UserPersonalData( - username=user.username, - email=user.email, - name=user.profile.name, - ), - id=user.id, - is_active=user.is_active, - ), + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.profile.name, + ), + id=user.id, + is_active=user.is_active, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index b00702ee25..c8bfa08290 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -44,6 +44,7 @@ from openedx.core.lib.api.test_utils import ApiTestCase from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerUserFactory from common.djangoapps.student.models import LoginFailures from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH +from common.test.utils import assert_dict_contains_subset @ddt.ddt @@ -544,7 +545,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase, OpenEdxEventsTestMixin): expected = { 'target': '/', } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) @patch.dict("django.conf.settings.FEATURES", {'SQUELCH_PII_IN_LOGS': True}) def test_logout_logging_no_pii(self): diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py index 77c21c86e1..a81d11c42c 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py @@ -14,6 +14,7 @@ from django.urls import reverse from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory from openedx.core.djangolib.testing.utils import skip_unless_lms from common.djangoapps.student.tests.factories import UserFactory +from common.test.utils import assert_dict_contains_subset @skip_unless_lms @@ -76,14 +77,14 @@ class LogoutTests(TestCase): expected = { 'target': urllib.parse.unquote(redirect_url), } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) def test_no_redirect_supplied(self): response = self.client.get(reverse('logout'), HTTP_HOST='testserver') expected = { 'target': '/', } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) @ddt.data( ('https://www.amazon.org', 'edx.org'), @@ -100,7 +101,7 @@ class LogoutTests(TestCase): expected = { 'target': '/', } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) def test_client_logout(self): """ Verify the context includes a list of the logout URIs of the authenticated OpenID Connect clients. @@ -113,7 +114,7 @@ class LogoutTests(TestCase): 'logout_uris': [], 'target': '/', } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) @mock.patch( 'django.conf.settings.IDA_LOGOUT_URI_LIST', @@ -138,7 +139,7 @@ class LogoutTests(TestCase): 'logout_uris': expected_logout_uris, 'target': '/', } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) @mock.patch( 'django.conf.settings.IDA_LOGOUT_URI_LIST', @@ -161,7 +162,7 @@ class LogoutTests(TestCase): 'logout_uris': expected_logout_uris, 'target': '/', } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) def test_filter_referring_service(self): """ Verify that, if the user is directed to the logout page from a service, that service's logout URL @@ -174,7 +175,7 @@ class LogoutTests(TestCase): 'target': '/', 'show_tpa_logout_link': False, } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) def test_learner_portal_logout_having_idp_logout_url(self): """ @@ -194,7 +195,7 @@ class LogoutTests(TestCase): 'tpa_logout_url': idp_logout_url, 'show_tpa_logout_link': True, } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) @mock.patch('django.conf.settings.TPA_AUTOMATIC_LOGOUT_ENABLED', True) def test_automatic_tpa_logout_url_redirect(self): @@ -214,7 +215,7 @@ class LogoutTests(TestCase): expected = { 'target': idp_logout_url, } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) @mock.patch('django.conf.settings.TPA_AUTOMATIC_LOGOUT_ENABLED', True) def test_no_automatic_tpa_logout_without_logout_url(self): @@ -241,4 +242,4 @@ class LogoutTests(TestCase): expected = { 'target': nh3.clean(urllib.parse.unquote(redirect_url)), } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) diff --git a/openedx/features/enterprise_support/tests/test_logout.py b/openedx/features/enterprise_support/tests/test_logout.py index c83b67c3a5..cbec233977 100644 --- a/openedx/features/enterprise_support/tests/test_logout.py +++ b/openedx/features/enterprise_support/tests/test_logout.py @@ -19,6 +19,7 @@ from openedx.features.enterprise_support.tests import ( factories ) from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseServiceMockMixin +from common.test.utils import assert_dict_contains_subset @ddt.ddt @@ -60,7 +61,7 @@ class EnterpriseLogoutTests(EnterpriseServiceMockMixin, CacheIsolationTestCase, expected = { 'enterprise_target': enterprise_target, } - self.assertDictContainsSubset(expected, response.context_data) + assert_dict_contains_subset(self, expected, response.context_data) if enterprise_target: self.assertContains(response, 'We are signing you in.') diff --git a/xmodule/modulestore/tests/test_mixed_modulestore.py b/xmodule/modulestore/tests/test_mixed_modulestore.py index 1f4bcfac7b..a7fafaf8ad 100644 --- a/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -63,6 +63,7 @@ from xmodule.modulestore.xml_exporter import export_course_to_xml from xmodule.modulestore.xml_importer import LocationMixin, import_course_from_xml from xmodule.tests import DATA_DIR, CourseComparisonTest from xmodule.x_module import XModuleMixin +from common.test.utils import assert_dict_contains_subset if not settings.configured: settings.configure() @@ -813,15 +814,16 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): event_receiver.assert_called() - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": COURSE_CREATED, "sender": None, "course": CourseData( - course_key=test_course.id, - ), + course_key=test_course.id, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) @ddt.data(ModuleStoreEnum.Type.split) @@ -891,16 +893,17 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): self.store.publish(sequential.location, self.user_id) event_receiver.assert_called() - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": XBLOCK_PUBLISHED, "sender": None, "xblock_info": XBlockData( - usage_key=sequential.location, - block_type=sequential.location.block_type, - ), + usage_key=sequential.location, + block_type=sequential.location.block_type, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) @ddt.data(ModuleStoreEnum.Type.split) @@ -925,16 +928,17 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): self.store.delete_item(vertical.location, self.user_id) event_receiver.assert_called() - self.assertDictContainsSubset( + assert_dict_contains_subset( + self, { "signal": XBLOCK_DELETED, "sender": None, "xblock_info": XBlockData( - usage_key=vertical.location, - block_type=vertical.location.block_type, - ), + usage_key=vertical.location, + block_type=vertical.location.block_type, + ), }, - event_receiver.call_args.kwargs + event_receiver.call_args.kwargs, ) def setup_has_changes(self, default_ms): From ebaf5e64de3223b3ea00b9694abf4015c648f719 Mon Sep 17 00:00:00 2001 From: usamasadiq Date: Mon, 13 Oct 2025 19:00:45 +0500 Subject: [PATCH 2/3] fix: fix pylint warning --- .../tests/test_tasks_helper.py | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index 1f8e0b637d..4144dd9568 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -850,7 +850,11 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): """ with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - assert_dict_contains_subset(self, {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset( + self, + {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, + result + ) self.verify_rows_in_csv([ dict(list(zip( self.csv_header_row, @@ -876,7 +880,11 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): self.submit_student_answer(self.student_1.username, 'Problem1', ['Option 1']) with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - assert_dict_contains_subset(self, {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, result) + assert_dict_contains_subset( + self, + {'action_name': 'graded', 'attempted': 2, 'succeeded': 2, 'failed': 0}, + result + ) problem_name = 'Homework 1: Subsection - Problem1' header_row = self.csv_header_row + [problem_name + ' (Earned)', problem_name + ' (Possible)'] self.verify_rows_in_csv([ @@ -946,7 +954,11 @@ class TestProblemGradeReport(TestReportMixin, InstructorTaskModuleTestCase): self.submit_student_answer(self.student_1.username, 'Problem1', ['Option 1']) with patch(USE_ON_DISK_GRADE_REPORT, return_value=use_tempfile): result = ProblemGradeReport.generate(None, None, self.course.id, {}, 'graded') - assert_dict_contains_subset(self, {'action_name': 'graded', 'attempted': 3, 'succeeded': 3, 'failed': 0}, result) + assert_dict_contains_subset( + self, + {'action_name': 'graded', 'attempted': 3, 'succeeded': 3, 'failed': 0}, + result + ) problem_name = 'Homework 1: Subsection - Problem1' header_row = self.csv_header_row + [problem_name + ' (Earned)', problem_name + ' (Possible)'] self.verify_rows_in_csv([ @@ -1500,7 +1512,11 @@ class TestListMayEnroll(TestReportMixin, InstructorTaskCourseTestCase): result = upload_may_enroll_csv(None, None, self.course.id, task_input, 'calculated') # This assertion simply confirms that the generation completed with no errors num_enrollments = len(enrollments) - assert_dict_contains_subset(self, {'attempted': num_enrollments, 'succeeded': num_enrollments, 'failed': 0}, result) + assert_dict_contains_subset( + self, + {'attempted': num_enrollments, 'succeeded': num_enrollments, 'failed': 0}, + result + ) class MockDefaultStorage: From 8aa2970c519cc5fc59a0f003f8b5967964d1a802 Mon Sep 17 00:00:00 2001 From: usamasadiq Date: Mon, 13 Oct 2025 22:53:37 +0500 Subject: [PATCH 3/3] fix: fix pycodestyle error --- .../contentstore/views/tests/test_block.py | 8 +- .../djangoapps/student/tests/test_events.py | 150 +++++++++--------- .../certificates/tests/test_events.py | 108 ++++++------- lms/djangoapps/grades/tests/test_events.py | 90 +++++------ .../course_groups/tests/test_events.py | 28 ++-- .../user_authn/views/tests/test_events.py | 32 ++-- .../tests/test_mixed_modulestore.py | 16 +- 7 files changed, 216 insertions(+), 216 deletions(-) diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index e01263259b..2b21a9b9b9 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -870,10 +870,10 @@ class TestDuplicateItem(ItemTest, DuplicateHelper, OpenEdxEventsTestMixin): "signal": XBLOCK_DUPLICATED, "sender": None, "xblock_info": DuplicatedXBlockData( - usage_key=usage_key, - block_type=usage_key.block_type, - source_usage_key=self.vert_usage_key, - ), + usage_key=usage_key, + block_type=usage_key.block_type, + source_usage_key=self.vert_usage_key, + ), }, event_receiver.call_args.kwargs, ) diff --git a/common/djangoapps/student/tests/test_events.py b/common/djangoapps/student/tests/test_events.py index 9d57c8ca85..7c9d625118 100644 --- a/common/djangoapps/student/tests/test_events.py +++ b/common/djangoapps/student/tests/test_events.py @@ -278,23 +278,23 @@ class EnrollmentEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): "signal": COURSE_ENROLLMENT_CREATED, "sender": None, "enrollment": CourseEnrollmentData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.profile.name, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CourseData( - course_key=self.course.id, - display_name=self.course.display_name, - ), - mode=enrollment.mode, - is_active=enrollment.is_active, - creation_date=enrollment.created, - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.profile.name, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CourseData( + course_key=self.course.id, + display_name=self.course.display_name, + ), + mode=enrollment.mode, + is_active=enrollment.is_active, + creation_date=enrollment.created, + ), }, event_receiver.call_args.kwargs, ) @@ -322,23 +322,23 @@ class EnrollmentEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): "signal": COURSE_ENROLLMENT_CHANGED, "sender": None, "enrollment": CourseEnrollmentData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.profile.name, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CourseData( - course_key=self.course.id, - display_name=self.course.display_name, - ), - mode=enrollment.mode, - is_active=enrollment.is_active, - creation_date=enrollment.created, - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.profile.name, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CourseData( + course_key=self.course.id, + display_name=self.course.display_name, + ), + mode=enrollment.mode, + is_active=enrollment.is_active, + creation_date=enrollment.created, + ), }, event_receiver.call_args.kwargs, ) @@ -366,23 +366,23 @@ class EnrollmentEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): "signal": COURSE_UNENROLLMENT_COMPLETED, "sender": None, "enrollment": CourseEnrollmentData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.profile.name, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CourseData( - course_key=self.course.id, - display_name=self.course.display_name, - ), - mode=enrollment.mode, - is_active=False, - creation_date=enrollment.created, - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.profile.name, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CourseData( + course_key=self.course.id, + display_name=self.course.display_name, + ), + mode=enrollment.mode, + is_active=False, + creation_date=enrollment.created, + ), }, event_receiver.call_args.kwargs, ) @@ -440,18 +440,18 @@ class TestCourseAccessRoleEvents(TestCase, OpenEdxEventsTestMixin): "signal": COURSE_ACCESS_ROLE_ADDED, "sender": None, "course_access_role_data": CourseAccessRoleData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course_key=self.course_key, - org_key=self.course_key.org, - role=role._role_name, # pylint: disable=protected-access - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course_key=self.course_key, + org_key=self.course_key.org, + role=role._role_name, # pylint: disable=protected-access + ), }, event_receiver.call_args.kwargs, ) @@ -479,18 +479,18 @@ class TestCourseAccessRoleEvents(TestCase, OpenEdxEventsTestMixin): "signal": COURSE_ACCESS_ROLE_REMOVED, "sender": None, "course_access_role_data": CourseAccessRoleData( - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course_key=self.course_key, - org_key=self.course_key.org, - role=role._role_name, # pylint: disable=protected-access - ), + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course_key=self.course_key, + org_key=self.course_key.org, + role=role._role_name, # pylint: disable=protected-access + ), }, event_receiver.call_args.kwargs, ) diff --git a/lms/djangoapps/certificates/tests/test_events.py b/lms/djangoapps/certificates/tests/test_events.py index fb890c53dd..eb1f215e49 100644 --- a/lms/djangoapps/certificates/tests/test_events.py +++ b/lms/djangoapps/certificates/tests/test_events.py @@ -101,24 +101,24 @@ class CertificateEventTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): "signal": CERTIFICATE_CREATED, "sender": None, "certificate": CertificateData( - user=UserData( - pii=UserPersonalData( - username=certificate.user.username, - email=certificate.user.email, - name=certificate.user.profile.name, - ), - id=certificate.user.id, - is_active=certificate.user.is_active, - ), - course=CourseData( - course_key=certificate.course_id, - ), - mode=certificate.mode, - grade=certificate.grade, - current_status=certificate.status, - download_url=certificate.download_url, - name=certificate.name, - ), + user=UserData( + pii=UserPersonalData( + username=certificate.user.username, + email=certificate.user.email, + name=certificate.user.profile.name, + ), + id=certificate.user.id, + is_active=certificate.user.is_active, + ), + course=CourseData( + course_key=certificate.course_id, + ), + mode=certificate.mode, + grade=certificate.grade, + current_status=certificate.status, + download_url=certificate.download_url, + name=certificate.name, + ), }, event_receiver.call_args.kwargs, ) @@ -155,24 +155,24 @@ class CertificateEventTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): "signal": CERTIFICATE_CHANGED, "sender": None, "certificate": CertificateData( - user=UserData( - pii=UserPersonalData( - username=certificate.user.username, - email=certificate.user.email, - name=certificate.user.profile.name, - ), - id=certificate.user.id, - is_active=certificate.user.is_active, - ), - course=CourseData( - course_key=certificate.course_id, - ), - mode=certificate.mode, - grade=certificate.grade, - current_status=certificate.status, - download_url=certificate.download_url, - name=certificate.name, - ), + user=UserData( + pii=UserPersonalData( + username=certificate.user.username, + email=certificate.user.email, + name=certificate.user.profile.name, + ), + id=certificate.user.id, + is_active=certificate.user.is_active, + ), + course=CourseData( + course_key=certificate.course_id, + ), + mode=certificate.mode, + grade=certificate.grade, + current_status=certificate.status, + download_url=certificate.download_url, + name=certificate.name, + ), }, event_receiver.call_args.kwargs, ) @@ -208,24 +208,24 @@ class CertificateEventTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): "signal": CERTIFICATE_REVOKED, "sender": None, "certificate": CertificateData( - user=UserData( - pii=UserPersonalData( - username=certificate.user.username, - email=certificate.user.email, - name=certificate.user.profile.name, - ), - id=certificate.user.id, - is_active=certificate.user.is_active, - ), - course=CourseData( - course_key=certificate.course_id, - ), - mode=certificate.mode, - grade=certificate.grade, - current_status=certificate.status, - download_url=certificate.download_url, - name=certificate.name, - ), + user=UserData( + pii=UserPersonalData( + username=certificate.user.username, + email=certificate.user.email, + name=certificate.user.profile.name, + ), + id=certificate.user.id, + is_active=certificate.user.is_active, + ), + course=CourseData( + course_key=certificate.course_id, + ), + mode=certificate.mode, + grade=certificate.grade, + current_status=certificate.status, + download_url=certificate.download_url, + name=certificate.name, + ), }, event_receiver.call_args.kwargs, ) diff --git a/lms/djangoapps/grades/tests/test_events.py b/lms/djangoapps/grades/tests/test_events.py index 93c440bdb5..4b3063265a 100644 --- a/lms/djangoapps/grades/tests/test_events.py +++ b/lms/djangoapps/grades/tests/test_events.py @@ -97,17 +97,17 @@ class PersistentGradeEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixi "signal": PERSISTENT_GRADE_SUMMARY_CHANGED, "sender": None, "grade": PersistentCourseGradeData( - user_id=self.params["user_id"], - course=CourseData( - course_key=self.params["course_id"], - ), - course_edited_timestamp=self.params["course_edited_timestamp"], - course_version=self.params["course_version"], - grading_policy_hash='', - percent_grade=self.params["percent_grade"], - letter_grade=self.params["letter_grade"], - passed_timestamp=grade.passed_timestamp - ) + user_id=self.params["user_id"], + course=CourseData( + course_key=self.params["course_id"], + ), + course_edited_timestamp=self.params["course_edited_timestamp"], + course_version=self.params["course_version"], + grading_policy_hash='', + percent_grade=self.params["percent_grade"], + letter_grade=self.params["letter_grade"], + passed_timestamp=grade.passed_timestamp + ) }, event_receiver.call_args.kwargs, ) @@ -159,20 +159,20 @@ class CoursePassingStatusEventsTest(SharedModuleStoreTestCase, OpenEdxEventsTest "signal": COURSE_PASSING_STATUS_UPDATED, "sender": None, "course_passing_status": CoursePassingStatusData( - is_passing=True, - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.get_full_name(), - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CourseData( - course_key=self.course.id, - ), - ), + is_passing=True, + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.get_full_name(), + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CourseData( + course_key=self.course.id, + ), + ), }, event_receiver.call_args.kwargs, ) @@ -233,26 +233,26 @@ class CCXCoursePassingStatusEventsTest( "signal": CCX_COURSE_PASSING_STATUS_UPDATED, "sender": None, "course_passing_status": CcxCoursePassingStatusData( - is_passing=True, - user=UserData( - pii=UserPersonalData( - username=self.user.username, - email=self.user.email, - name=self.user.get_full_name(), - ), - id=self.user.id, - is_active=self.user.is_active, - ), - course=CcxCourseData( - ccx_course_key=self.ccx_locator, - master_course_key=self.course.id, - display_name="", - coach_email="", - start=None, - end=None, - max_students_allowed=self.ccx.max_student_enrollments_allowed, - ), - ), + is_passing=True, + user=UserData( + pii=UserPersonalData( + username=self.user.username, + email=self.user.email, + name=self.user.get_full_name(), + ), + id=self.user.id, + is_active=self.user.is_active, + ), + course=CcxCourseData( + ccx_course_key=self.ccx_locator, + master_course_key=self.course.id, + display_name="", + coach_email="", + start=None, + end=None, + max_students_allowed=self.ccx.max_student_enrollments_allowed, + ), + ), }, event_receiver.call_args.kwargs, ) diff --git a/openedx/core/djangoapps/course_groups/tests/test_events.py b/openedx/core/djangoapps/course_groups/tests/test_events.py index 40a04dea8c..f11e95088f 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_events.py +++ b/openedx/core/djangoapps/course_groups/tests/test_events.py @@ -97,20 +97,20 @@ class CohortEventTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin): "signal": COHORT_MEMBERSHIP_CHANGED, "sender": None, "cohort": CohortData( - user=UserData( - pii=UserPersonalData( - username=cohort_membership.user.username, - email=cohort_membership.user.email, - name=cohort_membership.user.profile.name, - ), - id=cohort_membership.user.id, - is_active=cohort_membership.user.is_active, - ), - course=CourseData( - course_key=cohort_membership.course_id, - ), - name=cohort_membership.course_user_group.name, - ), + user=UserData( + pii=UserPersonalData( + username=cohort_membership.user.username, + email=cohort_membership.user.email, + name=cohort_membership.user.profile.name, + ), + id=cohort_membership.user.id, + is_active=cohort_membership.user.is_active, + ), + course=CourseData( + course_key=cohort_membership.course_id, + ), + name=cohort_membership.course_user_group.name, + ), }, event_receiver.call_args.kwargs, ) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_events.py b/openedx/core/djangoapps/user_authn/views/tests/test_events.py index 4460e8c627..7efd4e4cf5 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_events.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_events.py @@ -90,14 +90,14 @@ class RegistrationEventTest(UserAPITestCase, OpenEdxEventsTestMixin): "signal": STUDENT_REGISTRATION_COMPLETED, "sender": None, "user": UserData( - pii=UserPersonalData( - username=user.username, - email=user.email, - name=user.profile.name, - ), - id=user.id, - is_active=user.is_active, - ), + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.profile.name, + ), + id=user.id, + is_active=user.is_active, + ), }, event_receiver.call_args.kwargs, ) @@ -173,14 +173,14 @@ class LoginSessionEventTest(UserAPITestCase, OpenEdxEventsTestMixin): "signal": SESSION_LOGIN_COMPLETED, "sender": None, "user": UserData( - pii=UserPersonalData( - username=user.username, - email=user.email, - name=user.profile.name, - ), - id=user.id, - is_active=user.is_active, - ), + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.profile.name, + ), + id=user.id, + is_active=user.is_active, + ), }, event_receiver.call_args.kwargs, ) diff --git a/xmodule/modulestore/tests/test_mixed_modulestore.py b/xmodule/modulestore/tests/test_mixed_modulestore.py index a7fafaf8ad..f82d1e57c5 100644 --- a/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -820,8 +820,8 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): "signal": COURSE_CREATED, "sender": None, "course": CourseData( - course_key=test_course.id, - ), + course_key=test_course.id, + ), }, event_receiver.call_args.kwargs, ) @@ -899,9 +899,9 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): "signal": XBLOCK_PUBLISHED, "sender": None, "xblock_info": XBlockData( - usage_key=sequential.location, - block_type=sequential.location.block_type, - ), + usage_key=sequential.location, + block_type=sequential.location.block_type, + ), }, event_receiver.call_args.kwargs, ) @@ -934,9 +934,9 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): "signal": XBLOCK_DELETED, "sender": None, "xblock_info": XBlockData( - usage_key=vertical.location, - block_type=vertical.location.block_type, - ), + usage_key=vertical.location, + block_type=vertical.location.block_type, + ), }, event_receiver.call_args.kwargs, )