From bfd75013a17eb75eb717020f7e83a75a7f55c394 Mon Sep 17 00:00:00 2001 From: Justin Hynes Date: Fri, 22 Apr 2022 14:29:50 -0400 Subject: [PATCH] chore: update instructor task names to use constants * Update various instructor task logic to use constants over strings when referring to instructor task names --- lms/djangoapps/instructor/tests/test_api.py | 9 ++-- lms/djangoapps/instructor/views/api.py | 5 +- lms/djangoapps/instructor_task/api.py | 51 ++++++++++--------- .../instructor_task/tests/factories.py | 3 +- .../instructor_task/tests/test_api.py | 51 ++++++++++++------- .../instructor_task/tests/test_api_helper.py | 5 +- .../instructor_task/tests/test_integration.py | 15 ++++-- .../instructor_task/tests/test_subtasks.py | 3 +- 8 files changed, 86 insertions(+), 56 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index e79397c262..f12cfdc429 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -87,6 +87,7 @@ from lms.djangoapps.instructor_task.api_helper import ( QueueConnectionError, generate_already_running_error_message ) +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.program_enrollments.tests.factories import ProgramEnrollmentFactory from openedx.core.djangoapps.course_date_signals.handlers import extract_dates from openedx.core.djangoapps.course_groups.cohorts import set_course_cohorted @@ -2664,7 +2665,7 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment response = self.client.post(url, {}) assert response.status_code == 200 # CSV generation already in progress: - task_type = 'may_enroll_info_csv' + task_type = InstructorTaskTypes.MAY_ENROLL_INFO_CSV already_running_status = generate_already_running_error_message(task_type) with patch('lms.djangoapps.instructor_task.api.submit_calculate_may_enroll_csv') as submit_task_function: error = AlreadyRunningError(already_running_status) @@ -2843,7 +2844,7 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment def test_get_ora2_responses_already_running(self): url = reverse('export_ora2_data', kwargs={'course_id': str(self.course.id)}) - task_type = 'export_ora2_data' + task_type = InstructorTaskTypes.EXPORT_ORA2_DATA already_running_status = generate_already_running_error_message(task_type) with patch('lms.djangoapps.instructor_task.api.submit_export_ora2_data') as mock_submit_ora2_task: @@ -2867,7 +2868,7 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment def test_get_ora2_submission_files_already_running(self): url = reverse('export_ora2_submission_files', kwargs={'course_id': str(self.course.id)}) - task_type = 'export_ora2_submission_files' + task_type = InstructorTaskTypes.EXPORT_ORA2_SUBMISSION_FILES already_running_status = generate_already_running_error_message(task_type) with patch( @@ -2889,7 +2890,7 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment def test_get_ora2_summary_responses_already_running(self): url = reverse('export_ora2_summary', kwargs={'course_id': str(self.course.id)}) - task_type = 'export_ora2_summary' + task_type = InstructorTaskTypes.EXPORT_ORA2_SUMMARY already_running_status = generate_already_running_error_message(task_type) with patch('lms.djangoapps.instructor_task.api.submit_export_ora2_summary') as mock_submit_ora2_task: diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 9651c0b397..a2fde5d20f 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -103,6 +103,7 @@ from lms.djangoapps.instructor.views.instructor_task_helpers import extract_emai from lms.djangoapps.instructor_analytics import basic as instructor_analytics_basic, csvs as instructor_analytics_csvs from lms.djangoapps.instructor_task import api as task_api from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError, QueueConnectionError +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import ReportStore from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort, is_course_cohorted @@ -2115,7 +2116,7 @@ def list_background_email_tasks(request, course_id): List background email tasks. """ course_id = CourseKey.from_string(course_id) - task_type = 'bulk_course_email' + task_type = InstructorTaskTypes.BULK_COURSE_EMAIL # Specifying for the history of a single task type tasks = task_api.get_instructor_task_history( course_id, @@ -2137,7 +2138,7 @@ def list_email_content(request, course_id): List the content of bulk emails sent """ course_id = CourseKey.from_string(course_id) - task_type = 'bulk_course_email' + task_type = InstructorTaskTypes.BULK_COURSE_EMAIL # First get tasks list of bulk emails sent emails = task_api.get_instructor_task_history(course_id, task_type=task_type) diff --git a/lms/djangoapps/instructor_task/api.py b/lms/djangoapps/instructor_task/api.py index 587781ab82..03ac9d0338 100644 --- a/lms/djangoapps/instructor_task/api.py +++ b/lms/djangoapps/instructor_task/api.py @@ -30,6 +30,7 @@ from lms.djangoapps.instructor_task.api_helper import ( submit_task, submit_scheduled_task, ) +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import InstructorTask, InstructorTaskSchedule, SCHEDULED from lms.djangoapps.instructor_task.tasks import ( calculate_grades_csv, @@ -120,7 +121,7 @@ def submit_rescore_problem_for_student(request, usage_key, student, only_if_high # check arguments: let exceptions return up to the caller. check_arguments_for_rescoring(usage_key) - task_type = 'rescore_problem_if_higher' if only_if_higher else 'rescore_problem' + task_type = InstructorTaskTypes.RESCORE_PROBLEM_IF_HIGHER if only_if_higher else InstructorTaskTypes.RESCORE_PROBLEM task_class = rescore_problem task_input, task_key = encode_problem_and_student_input(usage_key, student) task_input.update({'only_if_higher': only_if_higher}) @@ -142,7 +143,7 @@ def submit_override_score(request, usage_key, student, score): the problem is not a ScorableXBlock. """ check_arguments_for_overriding(usage_key, score) - task_type = override_problem_score.__name__ + task_type = InstructorTaskTypes.OVERRIDE_PROBLEM_SCORE task_class = override_problem_score task_input, task_key = encode_problem_and_student_input(usage_key, student) task_input['score'] = score @@ -166,7 +167,7 @@ def submit_rescore_problem_for_all_students(request, usage_key, only_if_higher=F check_arguments_for_rescoring(usage_key) # check to see if task is already running, and reserve it otherwise - task_type = 'rescore_problem_if_higher' if only_if_higher else 'rescore_problem' + task_type = InstructorTaskTypes.RESCORE_PROBLEM_IF_HIGHER if only_if_higher else InstructorTaskTypes.RESCORE_PROBLEM task_class = rescore_problem task_input, task_key = encode_problem_and_student_input(usage_key) task_input.update({'only_if_higher': only_if_higher}) @@ -192,7 +193,7 @@ def submit_rescore_entrance_exam_for_student(request, usage_key, student=None, o check_entrance_exam_problems_for_rescoring(usage_key) # check to see if task is already running, and reserve it otherwise - task_type = 'rescore_problem_if_higher' if only_if_higher else 'rescore_problem' + task_type = InstructorTaskTypes.RESCORE_PROBLEM_IF_HIGHER if only_if_higher else InstructorTaskTypes.RESCORE_PROBLEM task_class = rescore_problem task_input, task_key = encode_entrance_exam_and_student_input(usage_key, student) task_input.update({'only_if_higher': only_if_higher}) @@ -215,7 +216,7 @@ def submit_reset_problem_attempts_for_all_students(request, usage_key): # pylin # an exception will be raised. Let it pass up to the caller. modulestore().get_item(usage_key) - task_type = 'reset_problem_attempts' + task_type = InstructorTaskTypes.RESET_PROBLEM_ATTEMPTS task_class = reset_problem_attempts task_input, task_key = encode_problem_and_student_input(usage_key) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key) @@ -239,7 +240,7 @@ def submit_reset_problem_attempts_in_entrance_exam(request, usage_key, student): # check arguments: make sure entrance exam(section) exists for given usage_key modulestore().get_item(usage_key) - task_type = 'reset_problem_attempts' + task_type = InstructorTaskTypes.RESET_PROBLEM_ATTEMPTS task_class = reset_problem_attempts task_input, task_key = encode_entrance_exam_and_student_input(usage_key, student) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key) @@ -261,7 +262,7 @@ def submit_delete_problem_state_for_all_students(request, usage_key): # pylint: # an exception will be raised. Let it pass up to the caller. modulestore().get_item(usage_key) - task_type = 'delete_problem_state' + task_type = InstructorTaskTypes.DELETE_PROBLEM_STATE task_class = delete_problem_state task_input, task_key = encode_problem_and_student_input(usage_key) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key) @@ -294,7 +295,7 @@ def submit_delete_entrance_exam_state_for_student(request, usage_key, student): relationship='fulfills' ) - task_type = 'delete_problem_state' + task_type = InstructorTaskTypes.DELETE_PROBLEM_STATE task_class = delete_problem_state task_input, task_key = encode_entrance_exam_and_student_input(usage_key, student) return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key) @@ -323,7 +324,7 @@ def submit_bulk_course_email(request, course_key, email_id, schedule=None): for target, count in targets.items() ] - task_type = 'bulk_course_email' + task_type = InstructorTaskTypes.BULK_COURSE_EMAIL task_class = send_bulk_course_email task_input = {'email_id': email_id, 'to_option': targets} task_key_stub = str(email_id) @@ -345,7 +346,7 @@ def submit_calculate_problem_responses_csv( Raises AlreadyRunningError if said file is already being updated. """ - task_type = 'problem_responses_csv' + task_type = InstructorTaskTypes.PROBLEM_RESPONSES_CSV task_class = calculate_problem_responses_csv task_input = { 'problem_locations': problem_locations, @@ -361,7 +362,7 @@ def submit_calculate_grades_csv(request, course_key, **task_kwargs): """ AlreadyRunningError is raised if the course's grades are already being updated. """ - task_type = 'grade_course' + task_type = InstructorTaskTypes.GRADE_COURSE task_class = calculate_grades_csv task_input = task_kwargs task_key = "" @@ -374,7 +375,7 @@ def submit_problem_grade_report(request, course_key, **task_kwargs): Submits a task to generate a CSV grade report containing problem values. """ - task_type = 'grade_problems' + task_type = InstructorTaskTypes.GRADE_PROBLEMS task_class = calculate_problem_grade_report task_input = task_kwargs task_key = "" @@ -387,7 +388,7 @@ def submit_calculate_students_features_csv(request, course_key, features, **task Raises AlreadyRunningError if said CSV is already being updated. """ - task_type = 'profile_info_csv' + task_type = InstructorTaskTypes.PROFILE_INFO_CSV task_class = calculate_students_features_csv task_input = dict(features=features, **task_kwargs) task_key = "" @@ -402,7 +403,7 @@ def submit_calculate_may_enroll_csv(request, course_key, features): Raises AlreadyRunningError if said file is already being updated. """ - task_type = 'may_enroll_info_csv' + task_type = InstructorTaskTypes.MAY_ENROLL_INFO_CSV task_class = calculate_may_enroll_csv task_input = {'features': features} task_key = "" @@ -416,7 +417,7 @@ def submit_course_survey_report(request, course_key): Raises AlreadyRunningError if HTML File is already being updated. """ - task_type = 'course_survey_report' + task_type = InstructorTaskTypes.COURSE_SURVEY_REPORT task_class = course_survey_report_csv task_input = {} task_key = "" @@ -430,7 +431,7 @@ def submit_proctored_exam_results_report(request, course_key): Raises AlreadyRunningError if HTML File is already being updated. """ - task_type = 'proctored_exam_results_report' + task_type = InstructorTaskTypes.PROCTORED_EXAM_RESULTS_REPORT task_class = proctored_exam_results_csv task_input = {} task_key = "" @@ -444,7 +445,7 @@ def submit_cohort_students(request, course_key, file_name): Raises AlreadyRunningError if students are currently being cohorted. """ - task_type = 'cohort_students' + task_type = InstructorTaskTypes.COHORT_STUDENTS task_class = cohort_students task_input = {'file_name': file_name} task_key = "" @@ -456,7 +457,7 @@ def submit_export_ora2_data(request, course_key): """ AlreadyRunningError is raised if an ora2 report is already being generated. """ - task_type = 'export_ora2_data' + task_type = InstructorTaskTypes.EXPORT_ORA2_DATA task_class = export_ora2_data task_input = {} task_key = '' @@ -469,7 +470,7 @@ def submit_export_ora2_submission_files(request, course_key): Submits a task to download and compress all submissions files (texts, attachments) for given course. """ - task_type = 'export_ora2_submission_files' + task_type = InstructorTaskTypes.EXPORT_ORA2_SUBMISSION_FILES task_class = export_ora2_submission_files task_input = {} task_key = '' @@ -481,7 +482,7 @@ def submit_export_ora2_summary(request, course_key): """ AlreadyRunningError is raised if an ora2 report is already being generated. """ - task_type = 'export_ora2_summary' + task_type = InstructorTaskTypes.EXPORT_ORA2_SUMMARY task_class = export_ora2_summary task_input = {} task_key = '' @@ -506,11 +507,11 @@ def generate_certificates_for_students(request, course_key, student_set=None, sp Raises SpecificStudentIdMissingError if student_set is 'specific_student' and specific_student_id is 'None' """ if student_set: - task_type = 'generate_certificates_student_set' + task_type = InstructorTaskTypes.GENERATE_CERTIFICATES_STUDENT_SET task_input = {'student_set': student_set} if student_set == 'specific_student': - task_type = 'generate_certificates_certain_student' + task_type = InstructorTaskTypes.GENERATE_CERTIFICATES_CERTAIN_STUDENT if specific_student_id is None: raise SpecificStudentIdMissingError( "Attempted to generate certificate for a single student, " @@ -518,7 +519,7 @@ def generate_certificates_for_students(request, course_key, student_set=None, sp ) task_input.update({'specific_student_id': specific_student_id}) else: - task_type = 'generate_certificates_all_student' + task_type = InstructorTaskTypes.GENERATE_CERTIFICATES_ALL_STUDENT task_input = {} task_class = generate_certificates @@ -543,7 +544,7 @@ def regenerate_certificates(request, course_key, statuses_to_regenerate): Raises AlreadyRunningError if certificates are currently being generated. """ - task_type = 'regenerate_certificates_all_student' + task_type = InstructorTaskTypes.REGENERATE_CERTIFICATES_ALL_STUDENT task_input = {} task_input.update({"statuses_to_regenerate": statuses_to_regenerate}) @@ -566,7 +567,7 @@ def generate_anonymous_ids(request, course_key): """ Generate anonymize id CSV report. """ - task_type = 'generate_anonymous_ids_for_course' + task_type = InstructorTaskTypes.GENERATE_ANONYMOUS_IDS_FOR_COURSE task_class = generate_anonymous_ids_for_course task_input = {} task_key = "" diff --git a/lms/djangoapps/instructor_task/tests/factories.py b/lms/djangoapps/instructor_task/tests/factories.py index b69a2a5667..1040d45f97 100644 --- a/lms/djangoapps/instructor_task/tests/factories.py +++ b/lms/djangoapps/instructor_task/tests/factories.py @@ -11,6 +11,7 @@ from factory.django import DjangoModelFactory from opaque_keys.edx.locator import CourseLocator from common.djangoapps.student.tests.factories import UserFactory as StudentUserFactory +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import InstructorTask, InstructorTaskSchedule @@ -21,7 +22,7 @@ class InstructorTaskFactory(DjangoModelFactory): class Meta: model = InstructorTask - task_type = 'rescore_problem' + task_type = InstructorTaskTypes.RESCORE_PROBLEM course_id = CourseLocator("MITx", "999", "Robot_Super_Course") task_input = json.dumps({}) task_key = None diff --git a/lms/djangoapps/instructor_task/tests/test_api.py b/lms/djangoapps/instructor_task/tests/test_api.py index 082227c968..0bfc8fa716 100644 --- a/lms/djangoapps/instructor_task/tests/test_api.py +++ b/lms/djangoapps/instructor_task/tests/test_api.py @@ -46,6 +46,7 @@ from lms.djangoapps.instructor_task.api import ( submit_reset_problem_attempts_in_entrance_exam, ) from lms.djangoapps.instructor_task.api_helper import AlreadyRunningError, QueueConnectionError +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import PROGRESS, SCHEDULED, InstructorTask from lms.djangoapps.instructor_task.tasks import ( export_ora2_data, @@ -93,7 +94,7 @@ class InstructorTaskReportTest(InstructorTaskTestCase): in get_instructor_task_history( TEST_COURSE_KEY, usage_key=self.problem_url, - task_type='rescore_problem' + task_type=InstructorTaskTypes.RESCORE_PROBLEM )] assert set(task_ids) == set(expected_ids) # make the same call using a non-existent task_type: @@ -142,29 +143,45 @@ class InstructorTaskModuleSubmitTest(InstructorTaskModuleTestCase): submit_rescore_problem_for_all_students(request, problem_url) @ddt.data( - (normalize_repr(submit_rescore_problem_for_all_students), 'rescore_problem'), + (normalize_repr(submit_rescore_problem_for_all_students), InstructorTaskTypes.RESCORE_PROBLEM), ( normalize_repr(submit_rescore_problem_for_all_students), - 'rescore_problem_if_higher', + InstructorTaskTypes.RESCORE_PROBLEM_IF_HIGHER, {'only_if_higher': True} ), - (normalize_repr(submit_rescore_problem_for_student), 'rescore_problem', {'student': True}), + (normalize_repr(submit_rescore_problem_for_student), InstructorTaskTypes.RESCORE_PROBLEM, {'student': True}), ( normalize_repr(submit_rescore_problem_for_student), - 'rescore_problem_if_higher', + InstructorTaskTypes.RESCORE_PROBLEM_IF_HIGHER, {'student': True, 'only_if_higher': True} ), - (normalize_repr(submit_reset_problem_attempts_for_all_students), 'reset_problem_attempts'), - (normalize_repr(submit_delete_problem_state_for_all_students), 'delete_problem_state'), - (normalize_repr(submit_rescore_entrance_exam_for_student), 'rescore_problem', {'student': True}), + (normalize_repr(submit_reset_problem_attempts_for_all_students), InstructorTaskTypes.RESET_PROBLEM_ATTEMPTS), + (normalize_repr(submit_delete_problem_state_for_all_students), InstructorTaskTypes.DELETE_PROBLEM_STATE), ( normalize_repr(submit_rescore_entrance_exam_for_student), - 'rescore_problem_if_higher', - {'student': True, 'only_if_higher': True}, + InstructorTaskTypes.RESCORE_PROBLEM, + {'student': True} ), - (normalize_repr(submit_reset_problem_attempts_in_entrance_exam), 'reset_problem_attempts', {'student': True}), - (normalize_repr(submit_delete_entrance_exam_state_for_student), 'delete_problem_state', {'student': True}), - (normalize_repr(submit_override_score), 'override_problem_score', {'student': True, 'score': 0}) + ( + normalize_repr(submit_rescore_entrance_exam_for_student), + InstructorTaskTypes.RESCORE_PROBLEM_IF_HIGHER, + {'student': True, 'only_if_higher': True} + ), + ( + normalize_repr(submit_reset_problem_attempts_in_entrance_exam), + InstructorTaskTypes.RESET_PROBLEM_ATTEMPTS, + {'student': True} + ), + ( + normalize_repr(submit_delete_entrance_exam_state_for_student), + InstructorTaskTypes.DELETE_PROBLEM_STATE, + {'student': True} + ), + ( + normalize_repr(submit_override_score), + InstructorTaskTypes.OVERRIDE_PROBLEM_SCORE, + {'student': True, 'score': 0} + ) ) @ddt.unpack def test_submit_task(self, task_function, expected_task_type, params=None): @@ -249,7 +266,7 @@ class InstructorTaskCourseSubmitTest(TestReportMixin, InstructorTaskCourseTestCa def _generate_scheduled_task(self, task_state=None): return InstructorTaskFactory.create( - task_type="bulk_course_email", + task_type=InstructorTaskTypes.BULK_COURSE_EMAIL, course_id=self.course.id, task_input="{'email_id': 1, 'to_option': ['myself']}", task_key="3416a75f4cea9109507cacd8e2f2aefc", @@ -337,7 +354,7 @@ class InstructorTaskCourseSubmitTest(TestReportMixin, InstructorTaskCourseTestCa submit_export_ora2_data(request, self.course.id) mock_submit_task.assert_called_once_with( - request, 'export_ora2_data', export_ora2_data, self.course.id, {}, '') + request, InstructorTaskTypes.EXPORT_ORA2_DATA, export_ora2_data, self.course.id, {}, '') def test_submit_export_ora2_submission_files(self): request = self.create_task_request(self.instructor) @@ -348,7 +365,7 @@ class InstructorTaskCourseSubmitTest(TestReportMixin, InstructorTaskCourseTestCa mock_submit_task.assert_called_once_with( request, - 'export_ora2_submission_files', + InstructorTaskTypes.EXPORT_ORA2_SUBMISSION_FILES, export_ora2_submission_files, self.course.id, {}, @@ -434,7 +451,7 @@ class InstructorTaskCourseSubmitTest(TestReportMixin, InstructorTaskCourseTestCa mock_submit_task.assert_called_once_with( request, - 'generate_anonymous_ids_for_course', + InstructorTaskTypes.GENERATE_ANONYMOUS_IDS_FOR_COURSE, generate_anonymous_ids_for_course, self.course.id, {}, diff --git a/lms/djangoapps/instructor_task/tests/test_api_helper.py b/lms/djangoapps/instructor_task/tests/test_api_helper.py index cbc566944b..6426388ca7 100644 --- a/lms/djangoapps/instructor_task/tests/test_api_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_api_helper.py @@ -14,6 +14,7 @@ from common.djangoapps.student.tests.factories import UserFactory from lms.djangoapps.bulk_email.api import create_course_email from lms.djangoapps.bulk_email.data import BulkEmailTargetChoices from lms.djangoapps.instructor_task.api_helper import QueueConnectionError, schedule_task, submit_scheduled_task +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import SCHEDULED, InstructorTask, InstructorTaskSchedule from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory, InstructorTaskScheduleFactory from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskCourseTestCase @@ -47,7 +48,7 @@ class ScheduledBulkEmailInstructorTaskTests(InstructorTaskCourseTestCase): self.targets = [BulkEmailTargetChoices.SEND_TO_MYSELF] self.course_email = self._create_course_email(self.targets) self.schedule = datetime.datetime.now(datetime.timezone.utc) - self.task_type = "bulk_course_email" + self.task_type = InstructorTaskTypes.BULK_COURSE_EMAIL self.task_input = json.dumps(self._generate_bulk_email_task_input(self.course_email, self.targets)) self.task_key = hashlib.md5(str(self.course_email.id).encode('utf-8')).hexdigest() @@ -150,7 +151,7 @@ class ScheduledInstructorTaskSubmissionTests(InstructorTaskCourseTestCase): # create an instructor task instance task_id = str(uuid4()) self.task = InstructorTaskFactory.create( - task_type="bulk_course_email", + task_type=InstructorTaskTypes.BULK_COURSE_EMAIL, course_id=self.course.id, task_input="{'email_id': 41, 'to_option': ['myself']}", task_key="3416a75f4cea9109507cacd8e2f2aefc", diff --git a/lms/djangoapps/instructor_task/tests/test_integration.py b/lms/djangoapps/instructor_task/tests/test_integration.py index c170b74f6e..72c07e201c 100644 --- a/lms/djangoapps/instructor_task/tests/test_integration.py +++ b/lms/djangoapps/instructor_task/tests/test_integration.py @@ -30,6 +30,7 @@ from lms.djangoapps.instructor_task.api import ( submit_rescore_problem_for_student, submit_reset_problem_attempts_for_all_students ) +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.models import InstructorTask from lms.djangoapps.instructor_task.tasks_helper.grades import CourseGradeReport from lms.djangoapps.instructor_task.tests.test_base import ( @@ -275,7 +276,9 @@ class TestRescoringTask(TestIntegrationTask): with patch('capa.capa_problem.LoncapaProblem.get_grade_from_current_answers') as mock_rescore: mock_rescore.side_effect = ZeroDivisionError(expected_message) instructor_task = self.submit_rescore_all_student_answers('instructor', problem_url_name) - self._assert_task_failure(instructor_task.id, 'rescore_problem', problem_url_name, expected_message) + self._assert_task_failure( + instructor_task.id, InstructorTaskTypes.RESCORE_PROBLEM, problem_url_name, expected_message + ) def test_rescoring_bad_unicode_input(self): """Generate a real failure in rescoring a problem, with an answer including unicode""" @@ -298,7 +301,7 @@ class TestRescoringTask(TestIntegrationTask): instructor_task = InstructorTask.objects.get(id=instructor_task.id) assert instructor_task.task_state == 'SUCCESS' assert instructor_task.requester.username == 'instructor' - assert instructor_task.task_type == 'rescore_problem' + assert instructor_task.task_type == InstructorTaskTypes.RESCORE_PROBLEM task_input = json.loads(instructor_task.task_input) assert 'student' not in task_input assert task_input['problem_url'] == str(InstructorTaskModuleTestCase.problem_location(problem_url_name)) @@ -490,7 +493,9 @@ class TestResetAttemptsTask(TestIntegrationTask): with patch('lms.djangoapps.courseware.models.StudentModule.save') as mock_save: mock_save.side_effect = ZeroDivisionError(expected_message) instructor_task = self.reset_problem_attempts('instructor', location) - self._assert_task_failure(instructor_task.id, 'reset_problem_attempts', problem_url_name, expected_message) + self._assert_task_failure( + instructor_task.id, InstructorTaskTypes.RESET_PROBLEM_ATTEMPTS, problem_url_name, expected_message + ) def test_reset_non_problem(self): """confirm that a non-problem can still be successfully reset""" @@ -552,7 +557,9 @@ class TestDeleteProblemTask(TestIntegrationTask): with patch('lms.djangoapps.courseware.models.StudentModule.delete') as mock_delete: mock_delete.side_effect = ZeroDivisionError(expected_message) instructor_task = self.delete_problem_state('instructor', location) - self._assert_task_failure(instructor_task.id, 'delete_problem_state', problem_url_name, expected_message) + self._assert_task_failure( + instructor_task.id, InstructorTaskTypes.DELETE_PROBLEM_STATE, problem_url_name, expected_message + ) def test_delete_non_problem(self): """confirm that a non-problem can still be successfully deleted""" diff --git a/lms/djangoapps/instructor_task/tests/test_subtasks.py b/lms/djangoapps/instructor_task/tests/test_subtasks.py index b3e81236b9..e627facee5 100644 --- a/lms/djangoapps/instructor_task/tests/test_subtasks.py +++ b/lms/djangoapps/instructor_task/tests/test_subtasks.py @@ -7,6 +7,7 @@ from unittest.mock import Mock, patch from uuid import uuid4 from common.djangoapps.student.models import CourseEnrollment +from lms.djangoapps.instructor_task.data import InstructorTaskTypes from lms.djangoapps.instructor_task.subtasks import queue_subtasks_for_query from lms.djangoapps.instructor_task.tests.factories import InstructorTaskFactory from lms.djangoapps.instructor_task.tests.test_base import InstructorTaskCourseTestCase @@ -34,7 +35,7 @@ class TestSubtasks(InstructorTaskCourseTestCase): course_id=self.course.id, task_id=task_id, task_key='dummy_task_key', - task_type='bulk_course_email', + task_type=InstructorTaskTypes.BULK_COURSE_EMAIL, ) self._enroll_students_in_course(self.course.id, initial_count)