def setUp(self): """ Fixtures. """ super(TestSetDueDateExtension, self).setUp() OverrideFieldData.provider_classes = None self.due = due = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=utc) course = CourseFactory.create() week1 = ItemFactory.create(due=due, parent=course) week2 = ItemFactory.create(due=due, parent=course) week3 = ItemFactory.create(parent=course) homework = ItemFactory.create(parent=week1) assignment = ItemFactory.create(parent=homework, due=due) user = UserFactory.create() self.course = course self.week1 = week1 self.homework = homework self.assignment = assignment self.week2 = week2 self.week3 = week3 self.user = user # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. for block in (course, week1, week2, week3, homework, assignment): block._field_data = OverrideFieldData.wrap( # pylint: disable=protected-access user, block._field_data) # pylint: disable=protected-access
def setUp(self): """ Fixtures. """ super(TestSetDueDateExtension, self).setUp() OverrideFieldData.provider_classes = None self.due = due = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=utc) course = CourseFactory.create() week1 = ItemFactory.create(due=due, parent=course) week2 = ItemFactory.create(due=due, parent=course) week3 = ItemFactory.create(parent=course) homework = ItemFactory.create(parent=week1) assignment = ItemFactory.create(parent=homework, due=due) user = UserFactory.create() self.course = course self.week1 = week1 self.homework = homework self.assignment = assignment self.week2 = week2 self.week3 = week3 self.user = user # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. for block in (course, week1, week2, week3, homework, assignment): block._field_data = OverrideFieldData.wrap( # pylint: disable=protected-access user, course, block._field_data) # pylint: disable=protected-access
def setUp(self): """ Set up tests """ super(TestFieldOverrides, self).setUp() self.course = course = CourseFactory.create() # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime(2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ ItemFactory.create(start=start, parent=course) for _ in xrange(2) ] sequentials = flatten( [[ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten([[ ItemFactory.create(due=due, parent=sequential) for _ in xrange(2) ] for sequential in sequentials]) blocks = flatten([ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals ]) self.ccx = ccx = CustomCourseForEdX(course_id=course.id, display_name='Test CCX', coach=AdminFactory.create()) ccx.save() patch = mock.patch('ccx.overrides.get_current_ccx') self.get_ccx = get_ccx = patch.start() get_ccx.return_value = ccx self.addCleanup(patch.stop) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None for block in iter_blocks(course): block._field_data = OverrideFieldData.wrap( # pylint: disable=protected-access AdminFactory.create(), block._field_data) # pylint: disable=protected-access def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes)
def setUp(self): """ Set up tests """ super(TestFieldOverrides, self).setUp() self.course = course = CourseFactory.create() self.course.enable_ccx = True # Create a course outline self.mooc_start = start = datetime.datetime( 2010, 5, 12, 2, 42, tzinfo=pytz.UTC) self.mooc_due = due = datetime.datetime( 2010, 7, 7, 0, 0, tzinfo=pytz.UTC) chapters = [ItemFactory.create(start=start, parent=course) for _ in xrange(2)] sequentials = flatten([ [ItemFactory.create(parent=chapter) for _ in xrange(2)] for chapter in chapters]) verticals = flatten([ [ItemFactory.create(due=due, parent=sequential) for _ in xrange(2)] for sequential in sequentials]) blocks = flatten([ # pylint: disable=unused-variable [ItemFactory.create(parent=vertical) for _ in xrange(2)] for vertical in verticals]) self.ccx = ccx = CustomCourseForEdX( course_id=course.id, display_name='Test CCX', coach=AdminFactory.create()) ccx.save() patch = mock.patch('ccx.overrides.get_current_ccx') self.get_ccx = get_ccx = patch.start() get_ccx.return_value = ccx self.addCleanup(patch.stop) self.addCleanup(RequestCache.clear_request_cache) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None for block in iter_blocks(ccx.course): block._field_data = OverrideFieldData.wrap( # pylint: disable=protected-access AdminFactory.create(), course, block._field_data) # pylint: disable=protected-access def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes)
def setUp(self): """ Set up tests """ super(TestCCXGrades, self).setUp() self.course = course = CourseFactory.create() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) chapter = ItemFactory.create(start=start, parent=course, category='sequential') sections = [ ItemFactory.create(parent=chapter, category="sequential", metadata={ 'graded': True, 'format': 'Homework' }) for _ in xrange(4) ] role = CourseCcxCoachRole(self.course.id) role.add_users(coach) self.ccx = ccx = CcxFactory(course_id=self.course.id, coach=self.coach) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CcxMembershipFactory(ccx=ccx, student=student, active=True) for i, section in enumerate(sections): for j in xrange(4): item = ItemFactory.create( parent=section, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) StudentModuleFactory.create(grade=1 if i < j else 0, max_grade=1, student=student, course_id=self.course.id, module_state_key=item.location) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None # pylint: disable=protected-access for block in iter_blocks(course): block._field_data = OverrideFieldData.wrap(coach, block._field_data) new_cache = {'tabs': [], 'discussion_topics': []} if 'grading_policy' in block._field_data_cache: new_cache['grading_policy'] = block._field_data_cache[ 'grading_policy'] block._field_data_cache = new_cache def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes) patch_context = patch('ccx.views.get_course_by_id') get_course = patch_context.start() get_course.return_value = course self.addCleanup(patch_context.stop) override_field_for_ccx( ccx, course, 'grading_policy', { 'GRADER': [{ 'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'weight': 1 }], 'GRADE_CUTOFFS': { 'Pass': 0.75 }, }) override_field_for_ccx(ccx, sections[-1], 'visible_to_staff_only', True)
def setUp(self): """ Set up tests """ super(TestCCXGrades, self).setUp() self.course = course = CourseFactory.create() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime( 2010, 5, 12, 2, 42, tzinfo=pytz.UTC) chapter = ItemFactory.create( start=start, parent=course, category='sequential') sections = [ ItemFactory.create( parent=chapter, category="sequential", metadata={'graded': True, 'format': 'Homework'}) for _ in xrange(4)] role = CourseCcxCoachRole(self.course.id) role.add_users(coach) self.ccx = ccx = CcxFactory(course_id=self.course.id, coach=self.coach) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CcxMembershipFactory(ccx=ccx, student=student, active=True) for i, section in enumerate(sections): for j in xrange(4): item = ItemFactory.create( parent=section, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=student, course_id=self.course.id, module_state_key=item.location ) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None # pylint: disable=protected-access for block in iter_blocks(course): block._field_data = OverrideFieldData.wrap(coach, block._field_data) new_cache = {'tabs': [], 'discussion_topics': []} if 'grading_policy' in block._field_data_cache: new_cache['grading_policy'] = block._field_data_cache['grading_policy'] block._field_data_cache = new_cache def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes) patch_context = patch('ccx.views.get_course_by_id') get_course = patch_context.start() get_course.return_value = course self.addCleanup(patch_context.stop) override_field_for_ccx(ccx, course, 'grading_policy', { 'GRADER': [ {'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'weight': 1} ], 'GRADE_CUTOFFS': {'Pass': 0.75}, }) override_field_for_ccx( ccx, sections[-1], 'visible_to_staff_only', True)
def setUp(self): """ Set up a course with graded problems. Course hierarchy is as follows: -> course -> chapter -> vertical (graded) -> problem -> problem """ super(TestCCXGradesVertical, self).setUp() self.course = course = CourseFactory.create(enable_ccx=True) # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) chapter = ItemFactory.create(start=start, parent=course) verticals = [ ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.5 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.2 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.2 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.1 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 1.0 }), ] # pylint: disable=unused-variable problems = [[ ItemFactory.create( parent=section, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) for _ in xrange(4) ] for section in verticals] # Create CCX role = CourseCcxCoachRole(course.id) role.add_users(coach) ccx = CcxFactory(course_id=course.id, coach=self.coach) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None # pylint: disable=protected-access for block in iter_blocks(course): block._field_data = OverrideFieldData.wrap(coach, course, block._field_data) new_cache = {'tabs': [], 'discussion_topics': []} if 'grading_policy' in block._field_data_cache: new_cache['grading_policy'] = block._field_data_cache[ 'grading_policy'] block._field_data_cache = new_cache def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes) # override course grading policy and make last section invisible to students override_field_for_ccx( ccx, course, 'grading_policy', { 'GRADER': [{ 'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'passing_grade': 0, 'weight': 1 }], 'GRADE_CUTOFFS': { 'Pass': 0.75 }, }) override_field_for_ccx(ccx, verticals[-1], 'visible_to_staff_only', True) # create a ccx locator and retrieve the course structure using that key # which emulates how a student would get access. self.ccx_key = CCXLocator.from_course_locator(course.id, ccx.id) self.course = get_course_by_id(self.ccx_key) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CcxMembershipFactory(ccx=ccx, student=student, active=True) # create grades for self.student as if they'd submitted the ccx for chapter in self.course.get_children(): for i, vertical in enumerate(chapter.get_children()): for j, problem in enumerate(vertical.get_children()): # if not problem.visible_to_staff_only: StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=self.student, course_id=self.course.id, module_state_key=problem.location) self.client.login(username=coach.username, password="******")
def setUp(self): """ Set up a course with graded problems. Course hierarchy is as follows: -> course -> chapter -> vertical (graded) -> problem -> problem """ super(TestCCXGradesVertical, self).setUp() self.course = course = CourseFactory.create(enable_ccx=True) # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime( 2010, 5, 12, 2, 42, tzinfo=pytz.UTC) chapter = ItemFactory.create(start=start, parent=course) verticals = [ ItemFactory.create( parent=chapter, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.5} ), ItemFactory.create( parent=chapter, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.2} ), ItemFactory.create( parent=chapter, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.2} ), ItemFactory.create( parent=chapter, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.1} ), ItemFactory.create( parent=chapter, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 1.0} ), ] # pylint: disable=unused-variable problems = [ [ ItemFactory.create( parent=section, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) for _ in xrange(4) ] for section in verticals ] # Create CCX role = CourseCcxCoachRole(course.id) role.add_users(coach) ccx = CcxFactory(course_id=course.id, coach=self.coach) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None # pylint: disable=protected-access for block in iter_blocks(course): block._field_data = OverrideFieldData.wrap(coach, course, block._field_data) new_cache = {'tabs': [], 'discussion_topics': []} if 'grading_policy' in block._field_data_cache: new_cache['grading_policy'] = block._field_data_cache['grading_policy'] block._field_data_cache = new_cache def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes) # override course grading policy and make last section invisible to students override_field_for_ccx(ccx, course, 'grading_policy', { 'GRADER': [ {'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'passing_grade': 0, 'weight': 1} ], 'GRADE_CUTOFFS': {'Pass': 0.75}, }) override_field_for_ccx( ccx, verticals[-1], 'visible_to_staff_only', True) # create a ccx locator and retrieve the course structure using that key # which emulates how a student would get access. self.ccx_key = CCXLocator.from_course_locator(course.id, ccx.id) self.course = get_course_by_id(self.ccx_key) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CcxMembershipFactory(ccx=ccx, student=student, active=True) # create grades for self.student as if they'd submitted the ccx for chapter in self.course.get_children(): for i, vertical in enumerate(chapter.get_children()): for j, problem in enumerate(vertical.get_children()): # if not problem.visible_to_staff_only: StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=self.student, course_id=self.course.id, module_state_key=problem.location ) self.client.login(username=coach.username, password="******")