def handle(self, *args, **options): create_report = options['create'] delete_report = options['delete'] if len(args) != 1: raise CommandError('"course_id" is not specified') elif create_report and delete_report: raise CommandError( 'Cannot specify "-c" option and "-d" option at the same time.') course_id = args[0] 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 delete_report: try: delete_pgreport_csv(course_id) except NotFoundError: raise CommandError("CSV not found.") call_command('create_report_task', *['clear_cache'], **{'course_id': course_id.to_deprecated_string()}) elif create_report: call_command('create_report_task', *['create'], **{'course_id': course_id.to_deprecated_string()}) else: try: get_pgreport_csv(course_id) except NotFoundError: raise CommandError("CSV not found.")
def handle(self, *args, **options): create_report = options['create'] delete_report = options['delete'] if len(args) != 1: raise CommandError('"course_id" is not specified') elif create_report and delete_report: raise CommandError( 'Cannot specify "-c" option and "-d" option at the same time.') course_id = args[0] 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 delete_report: try: delete_pgreport_csv(course_id) except NotFoundError: raise CommandError("CSV not found.") call_command('create_report_task', *['clear_cache'], **{'course_id': course_id.to_deprecated_string()}) elif create_report: call_command('create_report_task', *['create'], **{'course_id': course_id.to_deprecated_string()}) else: try: get_pgreport_csv(course_id) except NotFoundError: raise CommandError("CSV not found.")
def test_delete_pgreport_csv(self): cstore_mock = MagicMock() content_mock = MagicMock() with nested( patch('pgreport.views.StaticContent', return_value=content_mock), patch('pgreport.views.contentstore', return_value=cstore_mock), ) as (scmock, csmock): delete_pgreport_csv(self.course.id) scmock.compute_location.assert_called_once_with(ANY, "progress_students.csv.gz") csmock.assert_called_once_with() csmock.return_value.find.assert_called_once_with(ANY) csmock.return_value.delete.assert_called_once_with(ANY)
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)