def push_students_report(_xmodule_instance_args, _entry_id, course_id, _task_input, action_name): """ For a given `course_id`, generate a grades CSV file for all students """ start_time = datetime.now(UTC) status = True def update_task_progress(state): """Return a dict containing info about current task""" current_time = datetime.now(UTC) status, data = state.split(' ') attempted, total = data.split('/') entry = InstructorTask.objects.get(pk=_entry_id) progress = { 'action_name': action_name, 'attempted': int(attempted), 'succeeded': int(attempted), 'total': int(total), 'duration_ms': int((current_time - start_time).total_seconds() * 1000), } entry.task_state = PROGRESS entry.task_output = InstructorTask.create_output_for_success(progress) entry.save_now() #_get_current_task().update_state(state=status, meta=progress) create_pgreport_csv(course_id, update_task_progress)
def test_create_pgreport_csv(self): rows = [ ["username", "loc", "last_login"], [self.students[0].username, unicode(self.problems[0].location), "2014/1/1"], [self.students[1].username, unicode(self.problems[1].location), "2014/1/1"], ] progress_mock = MagicMock() progress_mock.get_raw.return_value = rows scontent_mock = MagicMock() cstore_mock = MagicMock() cstore_mock.fs.new_file().__exit__.return_value = False with nested( patch('pgreport.views.StaticContent', return_value=scontent_mock), patch('pgreport.views.contentstore', return_value=cstore_mock), patch('pgreport.views.ProgressReport', return_value=progress_mock), ) as (smock, cmock, pmock): create_pgreport_csv(self.course.id) smock.compute_location.assert_called_once_with(ANY, "progress_students.csv.gz") cmock.assert_called_once_with() cmock.return_value.find.assert_called_once_with(ANY) cmock.return_value.find.return_value.get_id.assert_called_once_with() progress_mock.get_raw.return_value = rows cstore_mock.fs.new_file().__enter__().write.side_effect = GridFSError() with nested( patch('pgreport.views.StaticContent', return_value=scontent_mock), patch('pgreport.views.contentstore', return_value=cstore_mock), patch('pgreport.views.ProgressReport', return_value=progress_mock), ) as (smock, cmock, pmock): with self.assertRaises(GridFSError): create_pgreport_csv(self.course.id)
def push_students_report(_xmodule_instance_args, _entry_id, course_id, _task_input, action_name): """ For a given `course_id`, generate a grades CSV file for all students """ start_time = datetime.now(UTC) status = True def update_task_progress(state): """Return a dict containing info about current task""" current_time = datetime.now(UTC) status, data = state.split(' ') attempted, total = data.split('/') entry = InstructorTask.objects.get(pk=_entry_id) progress = { 'action_name': action_name, 'attempted': int(attempted), 'succeeded': int(attempted), 'total': int(total), 'duration_ms': int( (current_time - start_time).total_seconds() * 1000), } entry.task_state = PROGRESS entry.task_output = InstructorTask.create_output_for_success(progress) entry.save_now() #_get_current_task().update_state(state=status, meta=progress) create_pgreport_csv(course_id, update_task_progress)
def create_report_task(task_id, course_id): """Create progress report.""" update_state = partial( create_report_task.update_state, task_id=task_id, meta={"hostname": socket.gethostname(), "pid": os.getpid()} ) try: create_pgreport_csv(course_id, update_state) except UserDoesNotExists as e: return "%s (%s)" % (e, course_id) return "Create complete!!! (%s)" % (course_id)
def i_am_staff_or_instructor(step, role): # pylint: disable=unused-argument ## In summary: makes a test course, makes a new Staff or Instructor user ## (depending on `role`), and logs that user in to the course # Store the role assert_in(role, ['instructor', 'staff']) # Clear existing courses to avoid conflicts delete_pgreport_csv("edx/999/Test_Course") world.clear_courses() # Create a new course world.scenario_dict['COURSE'] = world.CourseFactory.create( org='edx', number='999', display_name='Test Course' ) section1 = world.ItemFactory.create( parent_location=world.scenario_dict['COURSE'].location, category='chapter', display_name="Test Section 1" ) subsec1 = world.ItemFactory.create( parent_location=section1.location, category='sequential', display_name="Test Subsection 1" ) vertical1 = world.ItemFactory.create( parent_location=subsec1.location, category='vertical', display_name="Test Vertical 1", ) problem_xml = PROBLEM_DICT['drop down']['factory'].build_xml( **PROBLEM_DICT['drop down']['kwargs']) problem1 = world.ItemFactory.create( parent_location=vertical1.location, category='problem', display_name="Problem 1", data=problem_xml ) world.course_id = world.scenario_dict['COURSE'].id if not ProgressModules.objects.filter(location=problem1.location).exists(): world.pgmodule = world.ProgressModulesFactory.create( location=problem1.location, course_id=world.course_id, display_name="Problem 1" ) world.role = 'instructor' # Log in as the an instructor or staff for the course if role == 'instructor': # Make & register an instructor for the course world.instructor = InstructorFactory( course_key=world.scenario_dict['COURSE'].course_key) world.enroll_user(world.instructor, world.course_key) world.log_in( username=world.instructor.username, password='******', email=world.instructor.email, name=world.instructor.profile.name ) else: world.role = 'staff' # Make & register a staff member world.staff = StaffFactory( course_key=world.scenario_dict['COURSE'].course_key) world.enroll_user(world.staff, world.course_key) world.log_in( username=world.staff.username, password='******', email=world.staff.email, name=world.staff.profile.name ) create_pgreport_csv(world.course_id)
def i_am_staff_or_instructor(step, role): # pylint: disable=unused-argument ## In summary: makes a test course, makes a new Staff or Instructor user ## (depending on `role`), and logs that user in to the course # Store the role assert_in(role, ['instructor', 'staff']) # Clear existing courses to avoid conflicts delete_pgreport_csv("edx/999/Test_Course") world.clear_courses() # Create a new course world.scenario_dict['COURSE'] = world.CourseFactory.create( org='edx', number='999', display_name='Test Course') section1 = world.ItemFactory.create( parent_location=world.scenario_dict['COURSE'].location, category='chapter', display_name="Test Section 1") subsec1 = world.ItemFactory.create(parent_location=section1.location, category='sequential', display_name="Test Subsection 1") vertical1 = world.ItemFactory.create( parent_location=subsec1.location, category='vertical', display_name="Test Vertical 1", ) problem_xml = PROBLEM_DICT['drop down']['factory'].build_xml( **PROBLEM_DICT['drop down']['kwargs']) problem1 = world.ItemFactory.create(parent_location=vertical1.location, category='problem', display_name="Problem 1", data=problem_xml) world.course_id = world.scenario_dict['COURSE'].id if not ProgressModules.objects.filter(location=problem1.location).exists(): world.pgmodule = world.ProgressModulesFactory.create( location=problem1.location, course_id=world.course_id, display_name="Problem 1") world.role = 'instructor' # Log in as the an instructor or staff for the course if role == 'instructor': # Make & register an instructor for the course world.instructor = InstructorFactory( course_key=world.scenario_dict['COURSE'].course_key) world.enroll_user(world.instructor, world.course_key) world.log_in(username=world.instructor.username, password='******', email=world.instructor.email, name=world.instructor.profile.name) else: world.role = 'staff' # Make & register a staff member world.staff = StaffFactory( course_key=world.scenario_dict['COURSE'].course_key) world.enroll_user(world.staff, world.course_key) world.log_in(username=world.staff.username, password='******', email=world.staff.email, name=world.staff.profile.name) create_pgreport_csv(world.course_id)