Best Python code snippet using lisa_python
api.py
Source:api.py
...89 check_arguments_for_rescoring(usage_key)90 task_type = 'rescore_problem'91 task_class = rescore_problem92 task_input, task_key = encode_problem_and_student_input(usage_key, student)93 return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)94def submit_rescore_problem_for_all_students(request, usage_key): # pylint: disable=invalid-name95 """96 Request a problem to be rescored as a background task.97 The problem will be rescored for all students who have accessed the98 particular problem in a course and have provided and checked an answer.99 Parameters are the `course_id` and the `problem_url`.100 The url must specify the location of the problem, using i4x-type notation.101 ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError102 if the problem is already being rescored, or NotImplementedError if the problem doesn't103 support rescoring.104 """105 # check arguments: let exceptions return up to the caller.106 check_arguments_for_rescoring(usage_key)107 # check to see if task is already running, and reserve it otherwise108 task_type = 'rescore_problem'109 task_class = rescore_problem110 task_input, task_key = encode_problem_and_student_input(usage_key)111 return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)112def submit_rescore_entrance_exam_for_student(request, usage_key, student=None): # pylint: disable=invalid-name113 """114 Request entrance exam problems to be re-scored as a background task.115 The entrance exam problems will be re-scored for given student or if student116 is None problems for all students who have accessed the entrance exam.117 Parameters are `usage_key`, which must be a :class:`Location`118 representing entrance exam section and the `student` as a User object.119 ItemNotFoundError is raised if entrance exam does not exists for given120 usage_key, AlreadyRunningError is raised if the entrance exam121 is already being re-scored, or NotImplementedError if the problem doesn't122 support rescoring.123 """124 # check problems for rescoring: let exceptions return up to the caller.125 check_entrance_exam_problems_for_rescoring(usage_key)126 # check to see if task is already running, and reserve it otherwise127 task_type = 'rescore_problem'128 task_class = rescore_problem129 task_input, task_key = encode_entrance_exam_and_student_input(usage_key, student)130 return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)131def submit_reset_problem_attempts_for_all_students(request, usage_key): # pylint: disable=invalid-name132 """133 Request to have attempts reset for a problem as a background task.134 The problem's attempts will be reset for all students who have accessed the135 particular problem in a course. Parameters are the `course_id` and136 the `usage_key`, which must be a :class:`Location`.137 ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError138 if the problem is already being reset.139 """140 # check arguments: make sure that the usage_key is defined141 # (since that's currently typed in). If the corresponding module descriptor doesn't exist,142 # an exception will be raised. Let it pass up to the caller.143 modulestore().get_item(usage_key)144 task_type = 'reset_problem_attempts'145 task_class = reset_problem_attempts146 task_input, task_key = encode_problem_and_student_input(usage_key)147 return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)148def submit_reset_problem_attempts_in_entrance_exam(request, usage_key, student): # pylint: disable=invalid-name149 """150 Request to have attempts reset for a entrance exam as a background task.151 Problem attempts for all problems in entrance exam will be reset152 for specified student. If student is None problem attempts will be153 reset for all students.154 Parameters are `usage_key`, which must be a :class:`Location`155 representing entrance exam section and the `student` as a User object.156 ItemNotFoundError is raised if entrance exam does not exists for given157 usage_key, AlreadyRunningError is raised if the entrance exam158 is already being reset.159 """160 # check arguments: make sure entrance exam(section) exists for given usage_key161 modulestore().get_item(usage_key)162 task_type = 'reset_problem_attempts'163 task_class = reset_problem_attempts164 task_input, task_key = encode_entrance_exam_and_student_input(usage_key, student)165 return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)166def submit_delete_problem_state_for_all_students(request, usage_key): # pylint: disable=invalid-name167 """168 Request to have state deleted for a problem as a background task.169 The problem's state will be deleted for all students who have accessed the170 particular problem in a course. Parameters are the `course_id` and171 the `usage_key`, which must be a :class:`Location`.172 ItemNotFoundException is raised if the problem doesn't exist, or AlreadyRunningError173 if the particular problem's state is already being deleted.174 """175 # check arguments: make sure that the usage_key is defined176 # (since that's currently typed in). If the corresponding module descriptor doesn't exist,177 # an exception will be raised. Let it pass up to the caller.178 modulestore().get_item(usage_key)179 task_type = 'delete_problem_state'180 task_class = delete_problem_state181 task_input, task_key = encode_problem_and_student_input(usage_key)182 return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)183def submit_delete_entrance_exam_state_for_student(request, usage_key, student): # pylint: disable=invalid-name184 """185 Requests reset of state for entrance exam as a background task.186 Module state for all problems in entrance exam will be deleted187 for specified student.188 All User Milestones of entrance exam will be removed for the specified student189 Parameters are `usage_key`, which must be a :class:`Location`190 representing entrance exam section and the `student` as a User object.191 ItemNotFoundError is raised if entrance exam does not exists for given192 usage_key, AlreadyRunningError is raised if the entrance exam193 is already being reset.194 """195 # check arguments: make sure entrance exam(section) exists for given usage_key196 modulestore().get_item(usage_key)197 # Remove Content milestones that user has completed198 milestones_helpers.remove_course_content_user_milestones(199 course_key=usage_key.course_key,200 content_key=usage_key,201 user=student,202 relationship='fulfills'203 )204 task_type = 'delete_problem_state'205 task_class = delete_problem_state206 task_input, task_key = encode_entrance_exam_and_student_input(usage_key, student)207 return submit_task(request, task_type, task_class, usage_key.course_key, task_input, task_key)208def submit_bulk_course_email(request, course_key, email_id):209 """210 Request to have bulk email sent as a background task.211 The specified CourseEmail object will be sent be updated for all students who have enrolled212 in a course. Parameters are the `course_key` and the `email_id`, the id of the CourseEmail object.213 AlreadyRunningError is raised if the same recipients are already being emailed with the same214 CourseEmail object.215 """216 # Assume that the course is defined, and that the user has already been verified to have217 # appropriate access to the course. But make sure that the email exists.218 # We also pull out the targets argument here, so that is displayed in219 # the InstructorTask status.220 email_obj = CourseEmail.objects.get(id=email_id)221 # task_input has a limit to the size it can store, so any target_type with count > 1 is combined and counted222 targets = Counter([target.target_type for target in email_obj.targets.all()])223 targets = [224 target if count <= 1 else225 "{} {}".format(count, target)226 for target, count in targets.iteritems()227 ]228 task_type = 'bulk_course_email'229 task_class = send_bulk_course_email230 task_input = {'email_id': email_id, 'to_option': targets}231 task_key_stub = str(email_id)232 # create the key value by using MD5 hash:233 task_key = hashlib.md5(task_key_stub).hexdigest()234 return submit_task(request, task_type, task_class, course_key, task_input, task_key)235def submit_calculate_problem_responses_csv(request, course_key, problem_location): # pylint: disable=invalid-name236 """237 Submits a task to generate a CSV file containing all student238 answers to a given problem.239 Raises AlreadyRunningError if said file is already being updated.240 """241 task_type = 'problem_responses_csv'242 task_class = calculate_problem_responses_csv243 task_input = {'problem_location': problem_location}244 task_key = ""245 return submit_task(request, task_type, task_class, course_key, task_input, task_key)246def submit_calculate_grades_csv(request, course_key):247 """248 AlreadyRunningError is raised if the course's grades are already being updated.249 """250 task_type = 'grade_course'251 task_class = calculate_grades_csv252 task_input = {}253 task_key = ""254 return submit_task(request, task_type, task_class, course_key, task_input, task_key)255def submit_problem_grade_report(request, course_key):256 """257 Submits a task to generate a CSV grade report containing problem258 values.259 """260 task_type = 'grade_problems'261 task_class = calculate_problem_grade_report262 task_input = {}263 task_key = ""264 return submit_task(request, task_type, task_class, course_key, task_input, task_key)265def submit_calculate_students_features_csv(request, course_key, features):266 """267 Submits a task to generate a CSV containing student profile info.268 Raises AlreadyRunningError if said CSV is already being updated.269 """270 task_type = 'profile_info_csv'271 task_class = calculate_students_features_csv272 task_input = features273 task_key = ""274 return submit_task(request, task_type, task_class, course_key, task_input, task_key)275def submit_detailed_enrollment_features_csv(request, course_key): # pylint: disable=invalid-name276 """277 Submits a task to generate a CSV containing detailed enrollment info.278 Raises AlreadyRunningError if said CSV is already being updated.279 """280 task_type = 'detailed_enrollment_report'281 task_class = enrollment_report_features_csv282 task_input = {}283 task_key = ""284 return submit_task(request, task_type, task_class, course_key, task_input, task_key)285def submit_calculate_may_enroll_csv(request, course_key, features):286 """287 Submits a task to generate a CSV file containing information about288 invited students who have not enrolled in a given course yet.289 Raises AlreadyRunningError if said file is already being updated.290 """291 task_type = 'may_enroll_info_csv'292 task_class = calculate_may_enroll_csv293 task_input = {'features': features}294 task_key = ""295 return submit_task(request, task_type, task_class, course_key, task_input, task_key)296def submit_executive_summary_report(request, course_key):297 """298 Submits a task to generate a HTML File containing the executive summary report.299 Raises AlreadyRunningError if HTML File is already being updated.300 """301 task_type = 'exec_summary_report'302 task_class = exec_summary_report_csv303 task_input = {}304 task_key = ""305 return submit_task(request, task_type, task_class, course_key, task_input, task_key)306def submit_course_survey_report(request, course_key):307 """308 Submits a task to generate a HTML File containing the executive summary report.309 Raises AlreadyRunningError if HTML File is already being updated.310 """311 task_type = 'course_survey_report'312 task_class = course_survey_report_csv313 task_input = {}314 task_key = ""315 return submit_task(request, task_type, task_class, course_key, task_input, task_key)316def submit_proctored_exam_results_report(request, course_key, features): # pylint: disable=invalid-name317 """318 Submits a task to generate a HTML File containing the executive summary report.319 Raises AlreadyRunningError if HTML File is already being updated.320 """321 task_type = 'proctored_exam_results_report'322 task_class = proctored_exam_results_csv323 task_input = {'features': features}324 task_key = ""325 return submit_task(request, task_type, task_class, course_key, task_input, task_key)326def submit_cohort_students(request, course_key, file_name):327 """328 Request to have students cohorted in bulk.329 Raises AlreadyRunningError if students are currently being cohorted.330 """331 task_type = 'cohort_students'332 task_class = cohort_students333 task_input = {'file_name': file_name}334 task_key = ""335 return submit_task(request, task_type, task_class, course_key, task_input, task_key)336def submit_export_ora2_data(request, course_key):337 """338 AlreadyRunningError is raised if an ora2 report is already being generated.339 """340 task_type = 'export_ora2_data'341 task_class = export_ora2_data342 task_input = {}343 task_key = ''344 return submit_task(request, task_type, task_class, course_key, task_input, task_key)345def generate_certificates_for_students(request, course_key, student_set=None, specific_student_id=None): # pylint: disable=invalid-name346 """347 Submits a task to generate certificates for given students enrolled in the course.348 Arguments:349 course_key : Course Key350 student_set : Semantic for student collection for certificate generation.351 Options are:352 'all_whitelisted': All Whitelisted students.353 'whitelisted_not_generated': Whitelisted students which does not got certificates yet.354 'specific_student': Single student for certificate generation.355 specific_student_id : Student ID when student_set is 'specific_student'356 Raises AlreadyRunningError if certificates are currently being generated.357 Raises SpecificStudentIdMissingError if student_set is 'specific_student' and specific_student_id is 'None'358 """359 if student_set:360 task_type = 'generate_certificates_student_set'361 task_input = {'student_set': student_set}362 if student_set == 'specific_student':363 task_type = 'generate_certificates_certain_student'364 if specific_student_id is None:365 raise SpecificStudentIdMissingError(366 "Attempted to generate certificate for a single student, "367 "but no specific student id provided"368 )369 task_input.update({'specific_student_id': specific_student_id})370 else:371 task_type = 'generate_certificates_all_student'372 task_input = {}373 task_class = generate_certificates374 task_key = ""375 instructor_task = submit_task(request, task_type, task_class, course_key, task_input, task_key)376 CertificateGenerationHistory.objects.create(377 course_id=course_key,378 generated_by=request.user,379 instructor_task=instructor_task,380 is_regeneration=False381 )382 return instructor_task383def regenerate_certificates(request, course_key, statuses_to_regenerate):384 """385 Submits a task to regenerate certificates for given students enrolled in the course.386 Regenerate Certificate only if the status of the existing generated certificate is in 'statuses_to_regenerate'387 list passed in the arguments.388 Raises AlreadyRunningError if certificates are currently being generated.389 """390 task_type = 'regenerate_certificates_all_student'391 task_input = {}392 task_input.update({"statuses_to_regenerate": statuses_to_regenerate})393 task_class = generate_certificates394 task_key = ""395 instructor_task = submit_task(request, task_type, task_class, course_key, task_input, task_key)396 CertificateGenerationHistory.objects.create(397 course_id=course_key,398 generated_by=request.user,399 instructor_task=instructor_task,400 is_regeneration=True401 )...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!