Exemplo n.º 1
0
    def handle(self, *args, **options):
        """Handle command options."""
        course_id = options['course_id']
        task_id = options['task_id']

        if course_id is not None:
            try:
                course_id = CourseLocator.from_string(course_id)
            except InvalidKeyError:
                raise CommandError(
                    "'{}' is an invalid course_id".format(course_id))
            if not modulestore().get_course(course_id):
                raise CommandError("The specified course does not exist.")

        if len(args) != 1:
            raise CommandError(
                'Required subcommand, create, list, status, revoke or clear_cache.'
            )
        command = args[0]
        task = ProgressReportTask(create_report_task)

        if command == "status":
            if task_id is None:
                raise CommandError('"status" subcommand required task_id.')
            task.show_task_status(task_id)
        elif command == "list":
            task.show_task_list()
        elif command == "revoke":
            if task_id is None:
                raise CommandError('"revoke" subcommand required task_id.')
            task.revoke_task(task_id)
        elif command == "create":
            if course_id is None:
                raise CommandError('"create" subcommand required course_id.')
            task.send_task(course_id)
            state = TaskState("pgreport.tasks.create_report_task", course_id)
            state.delete_task_state()
        elif command == "clear_cache":
            if course_id is None:
                raise CommandError(
                    '"clear_cache" subcommand required course_id.')
            state = TaskState("pgreport.tasks.create_report_task", course_id)
            state.delete_task_state()
        else:
            raise CommandError('Invalid subcommand.')
Exemplo n.º 2
0
    def handle(self, *args, **options):
        """Handle command options."""
        course_id = options['course_id']
        task_id = options['task_id']

        if course_id is not None:
            try:
                course_id = CourseLocator.from_string(course_id)
            except InvalidKeyError:
                raise CommandError("'{}' is an invalid course_id".format(course_id))
            if not modulestore().get_course(course_id):
                raise CommandError("The specified course does not exist.")

        if len(args) != 1:
            raise CommandError(
                'Required subcommand, update, list, status, revoke or clear_cache.')
        command = args[0]
        task = ProgressReportTask(update_table_task)

        if command == "status":
            if task_id is None:
                raise CommandError('"status" subcommand required task_id.')
            task.show_task_status(task_id)
        elif command == "list":
            task.show_task_list()
        elif command == "revoke":
            if task_id is None:
                raise CommandError('"revoke" subcommand required task_id.')
            task.revoke_task(task_id)
        elif command == "update":
            if course_id:
                task.send_task(course_id.to_deprecated_string())
            else:
                task.send_tasks()
        elif command == "clear_cache":
            if course_id is None:
                raise CommandError('"clear_cache" subcommand required course_id.')
            state = TaskState("pgreport.tasks.update_table_task", course_id)
            state.delete_task_state()
        else:
            raise CommandError('Invalid subcommand.')
Exemplo n.º 3
0
 def test_revoke_task(self):
     task = ProgressReportTask(self.func_mock)
     task.revoke_task("task_id")    
     self.func_mock.AsyncResult.assert_called_once_with("task_id")
     self.func_mock.AsyncResult().revoke.assert_called_once_with(terminate=True)
Exemplo n.º 4
0
 def test_revoke_task(self):
     task = ProgressReportTask(self.func_mock)
     task.revoke_task("task_id")
     self.func_mock.AsyncResult.assert_called_once_with("task_id")
     self.func_mock.AsyncResult().revoke.assert_called_once_with(terminate=True)