'Unit tests for :meth: `contentstore.tasks.rerun_course`'

def test_rerun_course(self):

    mongo_course1_id = self.import_and_populate_course()
    split_course3_id = CourseLocator(org='edx3', course='split3', run='rerun_test')
    fields = {'display_name': 'rerun'}
    CourseRerunState.objects.initiated(mongo_course1_id, split_course3_id, self.user, fields['display_name'])
    result = rerun_course.delay(unicode(mongo_course1_id), unicode(split_course3_id), self.user.id, json.dumps(fields, cls=EdxJSONEncoder))
    self.assertEqual(result.get(), 'succeeded')
    self.assertTrue(has_course_author_access(self.user, split_course3_id), "Didn't    grant    access")
    rerun_state = CourseRerunState.objects.find_first(course_key=split_course3_id)
    self.assertEqual(rerun_state.state, CourseRerunUIStateManager.State.SUCCEEDED)
    result = rerun_course.delay(unicode(mongo_course1_id), unicode(split_course3_id), self.user.id)
    self.assertEqual(result.get(), 'duplicate    course')
    CourseRerunState.objects.find_first(course_key=split_course3_id, state=CourseRerunUIStateManager.State.FAILED)
    with patch('xmodule.modulestore.split_mongo.mongo_connection.MongoConnection.insert_course_index', Mock(side_effect=Exception)):
        split_course4_id = CourseLocator(org='edx3', course='split3', run='rerun_fail')
        fields = {'display_name': 'total    failure'}
        CourseRerunState.objects.initiated(split_course3_id, split_course4_id, self.user, fields['display_name'])
        result = rerun_course.delay(unicode(split_course3_id), unicode(split_course4_id), self.user.id, json.dumps(fields, cls=EdxJSONEncoder))
        self.assertIn('exception:    ', result.get())
        self.assertIsNone(self.store.get_course(split_course4_id), "Didn't    delete    course    after    error")
        CourseRerunState.objects.find_first(course_key=split_course4_id, state=CourseRerunUIStateManager.State.FAILED)
