'Tests submission of instructor task.'

@ddt.data((submit_rescore_problem_for_all_students, 'rescore_problem'), (submit_rescore_problem_for_all_students, 'rescore_problem_if_higher', {'only_if_higher': True}), (submit_rescore_problem_for_student, 'rescore_problem', {'student': True}), (submit_rescore_problem_for_student, 'rescore_problem_if_higher', {'student': True, 'only_if_higher': True}), (submit_reset_problem_attempts_for_all_students, 'reset_problem_attempts'), (submit_delete_problem_state_for_all_students, 'delete_problem_state'), (submit_rescore_entrance_exam_for_student, 'rescore_problem', {'student': True}), (submit_rescore_entrance_exam_for_student, 'rescore_problem_if_higher', {'student': True, 'only_if_higher': True}), (submit_reset_problem_attempts_in_entrance_exam, 'reset_problem_attempts', {'student': True}), (submit_delete_entrance_exam_state_for_student, 'delete_problem_state', {'student': True}), (submit_override_score, 'override_problem_score', {'student': True, 'score': 0}))
@ddt.unpack
def test_submit_task(self, task_function, expected_task_type, params=None):

    if (params is None):
        params = {}
    if params.get('student'):
        params['student'] = self.student
    problem_url_name = 'H1P1'
    self.define_option_problem(problem_url_name)
    location = InstructorTaskModuleTestCase.problem_location(problem_url_name)
    with patch('lms.djangoapps.instructor_task.tasks_base.BaseInstructorTask.apply_async') as apply_async:
        error = Exception()
        apply_async.side_effect = error
        with self.assertRaises(QueueConnectionError):
            instructor_task = task_function(self.create_task_request(self.instructor), location, **params)
        most_recent_task = InstructorTask.objects.latest('id')
        self.assertEquals(most_recent_task.task_state, FAILURE)
    instructor_task = task_function(self.create_task_request(self.instructor), location, **params)
    self.assertEquals(instructor_task.task_type, expected_task_type)
    instructor_task = InstructorTask.objects.get(id=instructor_task.id)
    instructor_task.task_state = PROGRESS
    instructor_task.save()
    with self.assertRaises(AlreadyRunningError):
        task_function(self.create_task_request(self.instructor), location, **params)
