Example #1
0
    def _queue_subtasks(self, create_subtask_fcn, items_per_task, initial_count, extra_count):
        """Queue subtasks while enrolling more students into course in the middle of the process."""

        task_id = str(uuid4())
        instructor_task = InstructorTaskFactory.create(
            course_id=self.course.id,
            task_id=task_id,
            task_key='dummy_task_key',
            task_type='bulk_course_email',
        )

        self._enroll_students_in_course(self.course.id, initial_count)
        task_querysets = [CourseEnrollment.objects.filter(course_id=self.course.id)]

        def initialize_subtask_info(*args):  # pylint: disable=unused-argument
            """Instead of initializing subtask info enroll some more students into course."""
            self._enroll_students_in_course(self.course.id, extra_count)
            return {}

        with patch('lms.djangoapps.instructor_task.subtasks.initialize_subtask_info') as mock_initialize_subtask_info:
            mock_initialize_subtask_info.side_effect = initialize_subtask_info
            queue_subtasks_for_query(
                entry=instructor_task,
                action_name='action_name',
                create_subtask_fcn=create_subtask_fcn,
                item_querysets=task_querysets,
                item_fields=[],
                items_per_task=items_per_task,
                total_num_items=initial_count,
            )
Example #2
0
    def _queue_subtasks(self, create_subtask_fcn, items_per_task,
                        initial_count, extra_count):
        """Queue subtasks while enrolling more students into course in the middle of the process."""

        task_id = str(uuid4())
        instructor_task = InstructorTaskFactory.create(
            course_id=self.course.id,
            task_id=task_id,
            task_key='dummy_task_key',
            task_type='bulk_course_email',
        )

        self._enroll_students_in_course(self.course.id, initial_count)
        task_querysets = [
            CourseEnrollment.objects.filter(course_id=self.course.id)
        ]

        def initialize_subtask_info(*args):  # pylint: disable=unused-argument
            """Instead of initializing subtask info enroll some more students into course."""
            self._enroll_students_in_course(self.course.id, extra_count)
            return {}

        with patch(
                'lms.djangoapps.instructor_task.subtasks.initialize_subtask_info'
        ) as mock_initialize_subtask_info:
            mock_initialize_subtask_info.side_effect = initialize_subtask_info
            queue_subtasks_for_query(
                entry=instructor_task,
                action_name='action_name',
                create_subtask_fcn=create_subtask_fcn,
                item_querysets=task_querysets,
                item_fields=[],
                items_per_task=items_per_task,
                total_num_items=initial_count,
            )
Example #3
0
 def setUp(self):
     super().setUp()
     self.initialize_course()
     self.instructor = UserFactory.create(username="******",
                                          email="*****@*****.**")
     # create an instructor task instance
     task_id = str(uuid4())
     self.task = InstructorTaskFactory.create(
         task_type="bulk_course_email",
         course_id=self.course.id,
         task_input="{'email_id': 41, 'to_option': ['myself']}",
         task_key="3416a75f4cea9109507cacd8e2f2aefc",
         task_id=task_id,
         task_state=SCHEDULED,
         task_output=None,
         requester=self.instructor)
     # associate the task with a instructor task schedule instance
     task_args = {
         "request_info": {
             "username": self.instructor.username,
             "user_id": self.instructor.id,
             "ip": "192.168.1.100",
             "agent": "Mozilla",
             "host": "localhost:18000"
         },
         "task_id": self.task.task_id
     }
     self.task_schedule = InstructorTaskScheduleFactory.create(
         task=self.task,
         task_args=json.dumps(task_args),
     )
Example #4
0
    def _create_input_entry(self,
                            student_ident=None,
                            use_problem_url=True,
                            course_id=None,
                            only_if_higher=False,
                            score=None,
                            include_email=True):
        """Creates a InstructorTask entry for testing."""
        task_id = str(uuid4())
        task_input = {'only_if_higher': only_if_higher}
        if use_problem_url:
            task_input['problem_url'] = self.location
        if student_ident is not None:
            task_input['student'] = student_ident
        if include_email:
            task_input['include_email'] = include_email
        if score is not None:
            task_input['score'] = score

        course_id = course_id or self.course.id
        instructor_task = InstructorTaskFactory.create(
            course_id=course_id,
            requester=self.instructor,
            task_input=json.dumps(task_input, cls=i4xEncoder),
            task_key='dummy value',
            task_id=task_id)
        return instructor_task
Example #5
0
 def _generate_scheduled_task(self, task_state=None):
     return InstructorTaskFactory.create(
         task_type="bulk_course_email",
         course_id=self.course.id,
         task_input="{'email_id': 1, 'to_option': ['myself']}",
         task_key="3416a75f4cea9109507cacd8e2f2aefc",
         task_id=str(uuid4()),
         task_state=task_state if task_state else SCHEDULED,
         task_output=None,
         requester=self.instructor)
 def test_get_task_name(self, is_regeneration, expected):
     staff = AdminFactory.create()
     instructor_task = InstructorTaskFactory.create(
         task_input=json.dumps({}), requester=staff, task_key=Mock(), task_id=Mock()
     )
     certificate_generation_history = CertificateGenerationHistory(
         course_id=instructor_task.course_id,
         generated_by=staff,
         instructor_task=instructor_task,
         is_regeneration=is_regeneration,
     )
     self.assertEqual(certificate_generation_history.get_task_name(), expected)
Example #7
0
    def _create_entry(self, task_state=QUEUING, task_output=None, student=None):
        """Creates a InstructorTask entry for testing."""
        task_id = str(uuid4())
        progress_json = json.dumps(task_output) if task_output is not None else None
        task_input, task_key = encode_problem_and_student_input(self.problem_url, student)

        instructor_task = InstructorTaskFactory.create(course_id=TEST_COURSE_KEY,
                                                       requester=self.instructor,
                                                       task_input=json.dumps(task_input),
                                                       task_key=task_key,
                                                       task_id=task_id,
                                                       task_state=task_state,
                                                       task_output=progress_json)
        return instructor_task
Example #8
0
    def _create_entry(self, task_state=QUEUING, task_output=None, student=None):
        """Creates a InstructorTask entry for testing."""
        task_id = str(uuid4())
        progress_json = json.dumps(task_output) if task_output is not None else None
        task_input, task_key = encode_problem_and_student_input(self.problem_url, student)

        instructor_task = InstructorTaskFactory.create(course_id=TEST_COURSE_KEY,
                                                       requester=self.instructor,
                                                       task_input=json.dumps(task_input),
                                                       task_key=task_key,
                                                       task_id=task_id,
                                                       task_state=task_state,
                                                       task_output=progress_json)
        return instructor_task
Example #9
0
    def setUp(self):
        super(TestFailOldQueueingTasksCommand, self).setUp()

        type_1_queueing = InstructorTaskFactory.create(
            task_state=QUEUING,
            task_type="type_1",
            task_key='',
            task_id=1,
        )
        type_1_progress = InstructorTaskFactory.create(
            task_state=PROGRESS,
            task_type="type_1",
            task_key='',
            task_id=2,
        )

        type_2_queueing = InstructorTaskFactory.create(
            task_state=QUEUING,
            task_type="type_2",
            task_key='',
            task_id=3,
        )
        self.tasks = [type_1_queueing, type_1_progress, type_2_queueing]
    def setUp(self):
        super(TestFailOldQueueingTasksCommand, self).setUp()

        type_1_queueing = InstructorTaskFactory.create(
            task_state=QUEUING,
            task_type="type_1",
            task_key='',
            task_id=1,
        )
        type_1_progress = InstructorTaskFactory.create(
            task_state=PROGRESS,
            task_type="type_1",
            task_key='',
            task_id=2,
        )

        type_2_queueing = InstructorTaskFactory.create(
            task_state=QUEUING,
            task_type="type_2",
            task_key='',
            task_id=3,
        )
        self.tasks = [type_1_queueing, type_1_progress, type_2_queueing]
Example #11
0
 def test_get_task_name(self, is_regeneration, expected):
     staff = AdminFactory.create()
     instructor_task = InstructorTaskFactory.create(
         task_input=json.dumps({}),
         requester=staff,
         task_key='',
         task_id='',
     )
     certificate_generation_history = CertificateGenerationHistory(
         course_id=instructor_task.course_id,
         generated_by=staff,
         instructor_task=instructor_task,
         is_regeneration=is_regeneration,
     )
     assert certificate_generation_history.get_task_name() == expected
Example #12
0
    def _create_input_entry(self, student_ident=None, use_problem_url=True, course_id=None, only_if_higher=False):
        """Creates a InstructorTask entry for testing."""
        task_id = str(uuid4())
        task_input = {'only_if_higher': only_if_higher}
        if use_problem_url:
            task_input['problem_url'] = self.location
        if student_ident is not None:
            task_input['student'] = student_ident

        course_id = course_id or self.course.id
        instructor_task = InstructorTaskFactory.create(course_id=course_id,
                                                       requester=self.instructor,
                                                       task_input=json.dumps(task_input, cls=i4xEncoder),
                                                       task_key='dummy value',
                                                       task_id=task_id)
        return instructor_task
Example #13
0
 def test_get_certificate_generation_candidates(self, task_input, expected, is_regeneration):
     staff = AdminFactory.create()
     instructor_task = InstructorTaskFactory.create(
         task_input=json.dumps(task_input),
         requester=staff,
         task_key='',
         task_id='',
     )
     certificate_generation_history = CertificateGenerationHistory(
         course_id=instructor_task.course_id,
         generated_by=staff,
         instructor_task=instructor_task,
         is_regeneration=is_regeneration,
     )
     self.assertEqual(
         certificate_generation_history.get_certificate_generation_candidates(),
         expected
     )
Example #14
0
 def test_get_certificate_generation_candidates(self, task_input, expected,
                                                is_regeneration):
     staff = AdminFactory.create()
     instructor_task = InstructorTaskFactory.create(
         task_input=json.dumps(task_input),
         requester=staff,
         task_key=Mock(),
         task_id=Mock(),
     )
     certificate_generation_history = CertificateGenerationHistory(
         course_id=instructor_task.course_id,
         generated_by=staff,
         instructor_task=instructor_task,
         is_regeneration=is_regeneration,
     )
     self.assertEqual(
         certificate_generation_history.
         get_certificate_generation_candidates(), expected)
Example #15
0
    def _create_input_entry(self,
                            student_ident=None,
                            use_problem_url=True,
                            course_id=None):
        """Creates a InstructorTask entry for testing."""
        task_id = str(uuid4())
        task_input = {}
        if use_problem_url:
            task_input['problem_url'] = self.location
        if student_ident is not None:
            task_input['student'] = student_ident

        course_id = course_id or self.course.id
        instructor_task = InstructorTaskFactory.create(
            course_id=course_id,
            requester=self.instructor,
            task_input=json.dumps(task_input, cls=i4xEncoder),
            task_key='dummy value',
            task_id=task_id)
        return instructor_task
Example #16
0
    def _create_input_entry(self, course_id=None):
        """
        Creates a InstructorTask entry for testing.

        Overrides the base class version in that this creates CourseEmail.
        """
        targets = [SEND_TO_MYSELF, SEND_TO_STAFF, SEND_TO_LEARNERS]
        course_id = course_id or self.course.id
        course_email = CourseEmail.create(course_id, self.instructor, targets,
                                          "Test Subject",
                                          "<p>This is a test message</p>")
        task_input = {'email_id': course_email.id}
        task_id = str(uuid4())
        instructor_task = InstructorTaskFactory.create(
            course_id=course_id,
            requester=self.instructor,
            task_input=json.dumps(task_input),
            task_key='dummy value',
            task_id=task_id,
        )
        return instructor_task
Example #17
0
    def _create_input_entry(self, course_id=None):
        """
        Creates a InstructorTask entry for testing.

        Overrides the base class version in that this creates CourseEmail.
        """
        targets = [SEND_TO_MYSELF, SEND_TO_STAFF, SEND_TO_LEARNERS]
        course_id = course_id or self.course.id
        course_email = CourseEmail.create(
            course_id, self.instructor, targets, "Test Subject", "<p>This is a test message</p>"
        )
        task_input = {'email_id': course_email.id}
        task_id = str(uuid4())
        instructor_task = InstructorTaskFactory.create(
            course_id=course_id,
            requester=self.instructor,
            task_input=json.dumps(task_input),
            task_key='dummy value',
            task_id=task_id,
        )
        return instructor_task
Example #18
0
 def _create_scheduled_course_emails_for_course(self, course_id,
                                                email_author, task_status,
                                                num_emails):
     """
     Utility function to create (bulk course email) scheduled instructor tasks for the test suite.
     """
     for i in range(1, (num_emails + 1)):
         # create the course email instance
         email = self._create_course_email(
             course_id, email_author,
             [BulkEmailTargetChoices.SEND_TO_MYSELF], f"Test Subject{i}",
             "<p>Test message.</p>")
         # associate the course_email instance with the task
         task_input = {'email_id': email.id}
         task_id = str(uuid4())
         task = InstructorTaskFactory.create(
             course_id=course_id,
             requester=email_author,
             task_id=task_id,
             task_input=json.dumps(task_input),
             task_key='dummy value',
             task_state=task_status,
             task_type=InstructorTaskTypes.BULK_COURSE_EMAIL)
         # associate the task with an instructor task schedule
         task_args = {
             "request_info": {
                 "username": self.instructor_course1.username,
                 "user_id": self.instructor_course1.id,
                 "ip": "192.168.1.100",
                 "agent": "Mozilla",
                 "host": "localhost:18000"
             },
             "task_id": task.task_id
         }
         InstructorTaskScheduleFactory.create(
             task=task,
             task_args=json.dumps(task_args),
         )