Ejemplo n.º 1
0
    def register_user_in_ccx(self):
        """create registration of self.user in self.ccx

        registration will be inactive
        """
        self.create_user()
        CcxMembershipFactory(ccx=self.ccx, student=self.user)
Ejemplo n.º 2
0
    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="******")
Ejemplo n.º 3
0
    def register_user_in_ccx(self, active=False):
        """create registration of self.user in self.ccx

        registration will be inactive unless active=True
        """
        CcxMembershipFactory(ccx=self.ccx, student=self.user, active=active)