def setUp(self):
     """Set up a course, coach, ccx and user"""
     super(TestGetCCXFromCCXLocator, self).setUp()
     self.course = CourseFactory.create()
     coach = self.coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
Example #2
0
 def setUp(self):
     super(TestRenderMessageToString, self).setUp()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
     self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
Example #3
0
    def setUp(self):
        """
        Set up courses and enrollments.
        """
        super(TestStudentViewsWithCCX, self).setUp()

        # Create a Draft Mongo and a Split Mongo course and enroll a student user in them.
        self.student_password = "******"
        self.student = UserFactory.create(username="******", password=self.student_password, is_staff=False)
        self.draft_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.mongo)
        self.split_course = SampleCourseFactory.create(default_store=ModuleStoreEnum.Type.split)
        CourseEnrollment.enroll(self.student, self.draft_course.id)
        CourseEnrollment.enroll(self.student, self.split_course.id)

        # Create a CCX coach.
        self.coach = AdminFactory.create()
        role = CourseCcxCoachRole(self.split_course.id)
        role.add_users(self.coach)

        # Create a CCX course and enroll the user in it.
        self.ccx = CcxFactory(course_id=self.split_course.id, coach=self.coach)
        last_week = datetime.datetime.now(UTC()) - datetime.timedelta(days=7)
        override_field_for_ccx(self.ccx, self.split_course, 'start', last_week)  # Required by self.ccx.has_started().
        self.ccx_course_key = CCXLocator.from_course_locator(self.split_course.id, self.ccx.id)
        CourseEnrollment.enroll(self.student, self.ccx_course_key)
Example #4
0
 def setUp(self):
     super(CCXCoachTabTestCase, self).setUp()
     self.user = UserFactory.create()
     for course in [self.ccx_enabled_course, self.ccx_disabled_course]:
         CourseEnrollmentFactory.create(user=self.user, course_id=course.id)
         role = CourseCcxCoachRole(course.id)
         role.add_users(self.user)
 def setUp(self):
     super(CCXCoachTabTestCase, self).setUp()
     self.course = CourseFactory.create()
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(self.user)
Example #6
0
 def setUp(self):
     """Set up a course, coach, ccx and user"""
     super(TestGetCCXFromCCXLocator, self).setUp()
     self.course = CourseFactory.create()
     coach = self.coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
Example #7
0
 def setUp(self):
     super(CCXCoachTabTestCase, self).setUp()
     self.user = UserFactory.create()
     for course in [self.ccx_enabled_course, self.ccx_disabled_course]:
         CourseEnrollmentFactory.create(user=self.user, course_id=course.id)
         role = CourseCcxCoachRole(course.id)
         role.add_users(self.user)
 def setUp(self):
     super(TestRenderMessageToString, self).setUp()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
     self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)
Example #9
0
    def setUp(self):
        """
        Set up courses and enrollments.
        """
        super(TestStudentViewsWithCCX, self).setUp()

        # Create a Draft Mongo and a Split Mongo course and enroll a student user in them.
        self.student_password = "******"
        self.student = UserFactory.create(username="******",
                                          password=self.student_password,
                                          is_staff=False)
        self.draft_course = SampleCourseFactory.create(
            default_store=ModuleStoreEnum.Type.mongo)
        self.split_course = SampleCourseFactory.create(
            default_store=ModuleStoreEnum.Type.split)
        CourseEnrollment.enroll(self.student, self.draft_course.id)
        CourseEnrollment.enroll(self.student, self.split_course.id)

        # Create a CCX coach.
        self.coach = AdminFactory.create()
        role = CourseCcxCoachRole(self.split_course.id)
        role.add_users(self.coach)

        # Create a CCX course and enroll the user in it.
        self.ccx = CcxFactory(course_id=self.split_course.id, coach=self.coach)
        last_week = datetime.datetime.now(UTC()) - datetime.timedelta(days=7)
        override_field_for_ccx(
            self.ccx, self.split_course, 'start',
            last_week)  # Required by self.ccx.has_started().
        self.ccx_course_key = CCXLocator.from_course_locator(
            self.split_course.id, self.ccx.id)
        CourseEnrollment.enroll(self.student, self.ccx_course_key)
Example #10
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, self).setUp()

        # Create instructor account
        self.coach = coach = AdminFactory.create()
        self.client.login(username=coach.username, password="******")

        # Create CCX
        role = CourseCcxCoachRole(self._course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=self._course.id, coach=self.coach)

        # override course grading policy and make last section invisible to students
        override_field_for_ccx(
            ccx,
            self._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, self.sections[-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(self._course.id, ccx.id)
        self.course = get_course_by_id(self.ccx_key, depth=None)
        setup_students_and_grades(self)
        self.client.login(username=coach.username, password="******")
        self.addCleanup(RequestCache.clear_request_cache)
Example #11
0
 def test_ccx_tab_visibility_for_instructor_when_coach_master_course(self):
     """
     Instructor can view ccx coach dashboard only if he is coach on master course.
     """
     instructor = self.make_instructor()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(instructor)
     self.assertTrue(self.check_ccx_tab(self.course, instructor))
 def setUp(self):
     """Set up a course, coach, ccx and user"""
     super(TestGetMembershipTriplets, self).setUp()
     self.course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
Example #13
0
 def setUp(self):
     super(CCXCoachTabTestCase, self).setUp()
     self.course = CourseFactory.create()
     self.user = UserFactory.create()
     CourseEnrollmentFactory.create(user=self.user,
                                    course_id=self.course.id)
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(self.user)
Example #14
0
 def test_ccx_tab_visibility_for_staff_when_coach_master_course(self):
     """
     Staff can view ccx coach dashboard only if he is coach on master course.
     """
     staff = self.make_staff()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(staff)
     self.assertTrue(self.check_ccx_tab(self.course, staff))
Example #15
0
 def setUp(self):
     """common setup for all tests"""
     super(TestCCX, self).setUp()
     self.course = course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
Example #16
0
 def setUp(self):
     """common setup for all tests"""
     super(TestCCX, self).setUp()
     self.course = course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
Example #17
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, self).setUp()

        # Create instructor account
        self.coach = coach = AdminFactory.create()
        self.client.login(username=coach.username, password="******")

        # Create CCX
        role = CourseCcxCoachRole(self._course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=self._course.id, coach=self.coach)

        # override course grading policy and make last section invisible to students
        override_field_for_ccx(
            ccx, self._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, self.sections[-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(self._course.id, ccx.id)
        self.course = get_course_by_id(self.ccx_key, depth=None)

        self.student = student = UserFactory.create()
        CourseEnrollmentFactory.create(user=student, course_id=self.course.id)

        # create grades for self.student as if they'd submitted the ccx
        for chapter in self.course.get_children():
            for i, section in enumerate(chapter.get_children()):
                for j, problem in enumerate(section.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="******")

        self.addCleanup(RequestCache.clear_request_cache)
Example #18
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, self).setUp()

        # Create instructor account
        self.coach = coach = AdminFactory.create()
        self.client.login(username=coach.username, password="******")

        # Create CCX
        role = CourseCcxCoachRole(self._course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=self._course.id, coach=self.coach)

        # override course grading policy and make last section invisible to students
        override_field_for_ccx(ccx, self._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, self.sections[-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(self._course.id, ccx.id)
        self.course = get_course_by_id(self.ccx_key, depth=None)

        self.student = student = UserFactory.create()
        CourseEnrollmentFactory.create(user=student, course_id=self.course.id)

        # create grades for self.student as if they'd submitted the ccx
        for chapter in self.course.get_children():
            for i, section in enumerate(chapter.get_children()):
                for j, problem in enumerate(section.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="******")

        self.addCleanup(RequestCache.clear_request_cache)
Example #19
0
 def setUp(self):
     """Create required infrastructure for tests"""
     super(TestUserCCXList, self).setUp()
     self.course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
     enrollment = CourseEnrollmentFactory.create(course_id=self.course.id)
     self.user = enrollment.user
     self.anonymous = AnonymousUserFactory.create()
 def setUp(self):
     super(TestEnrollEmail, self).setUp()
     # unbind the user created by the parent, so we can create our own when
     # needed.
     self.user = None
     course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
     self.outbox = self.get_outbox()
 def setUp(self):
     super(TestSwitchActiveCCX, self).setUp()
     self.course = course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
     enrollment = CourseEnrollmentFactory.create(course_id=course.id)
     self.user = enrollment.user
     self.target_url = reverse('course_root',
                               args=[course.id.to_deprecated_string()])
Example #22
0
 def setUp(self):
     """Create required infrastructure for tests"""
     super(TestUserCCXList, self).setUp()
     self.course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
     enrollment = CourseEnrollmentFactory.create(course_id=self.course.id)
     self.user = enrollment.user
     self.anonymous = AnonymousUserFactory.create()
Example #23
0
 def setUp(self):
     """common setup for all tests"""
     super(TestCcxMembership, self).setUp()
     self.course = course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
     enrollment = CourseEnrollmentFactory.create(course_id=course.id)
     self.enrolled_user = enrollment.user
     self.unenrolled_user = UserFactory.create()
Example #24
0
def make_user_coach(user, master_course_key):
    """
    Makes an user coach on the master course.
    This function is needed because an user cannot become a coach of the CCX if s/he is not
    coach on the master course.

    Args:
        user (User): User object
        master_course_key (CourseKey): Key locator object for the course
    """
    coach_role_on_master_course = CourseCcxCoachRole(master_course_key)
    coach_role_on_master_course.add_users(user)
Example #25
0
 def setUp(self):
     super(TestSwitchActiveCCX, self).setUp()
     self.course = course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
     enrollment = CourseEnrollmentFactory.create(course_id=course.id)
     self.user = enrollment.user
     self.target_url = reverse(
         'course_root', args=[course.id.to_deprecated_string()]
     )
Example #26
0
    def make_ccx(self):
        """
        create ccx
        """
        ccx = CustomCourseForEdX(course_id=self.course.id, coach=self.coach, display_name="Test CCX")
        ccx.save()

        ccx_locator = CCXLocator.from_course_locator(self.course.id, unicode(ccx.id))
        role = CourseCcxCoachRole(ccx_locator)
        role.add_users(self.coach)
        CourseEnrollment.enroll(self.coach, ccx_locator)
        return ccx_locator
Example #27
0
def make_user_coach(user, master_course_key):
    """
    Makes an user coach on the master course.
    This function is needed because an user cannot become a coach of the CCX if s/he is not
    coach on the master course.

    Args:
        user (User): User object
        master_course_key (CourseKey): Key locator object for the course
    """
    coach_role_on_master_course = CourseCcxCoachRole(master_course_key)
    coach_role_on_master_course.add_users(user)
 def setUp(self):
     """
     Set up tests
     """
     super(TestEmailEnrollmentState, self).setUp()
     # remove user provided by the parent test case so we can make our own
     # when needed.
     self.user = None
     course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
Example #29
0
    def setUp(self):
        super(TestGetEmailParamsCCX, self).setUp()
        self.coach = AdminFactory.create()
        role = CourseCcxCoachRole(self.course.id)
        role.add_users(self.coach)
        self.ccx = CcxFactory(course_id=self.course.id, coach=self.coach)
        self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)

        # Explicitly construct what we expect the course URLs to be
        site = settings.SITE_NAME
        self.course_url = u"https://{}/courses/{}/".format(site, self.course_key)
        self.course_about_url = self.course_url + "about"
        self.registration_url = u"https://{}/register".format(site)
Example #30
0
    def setUp(self):
        """
        Set up tests
        """
        super(CoachAccessTestCaseCCX, self).setUp()

        # Create ccx coach account
        self.coach = AdminFactory.create(password="******")
        self.client.login(username=self.coach.username, password="******")

        # assign role to coach
        role = CourseCcxCoachRole(self.course.id)
        role.add_users(self.coach)
        self.request_factory = RequestFactory()
Example #31
0
 def setUp(self):
     """
     Set up tests
     """
     super(TestSendCCXCoursePublished, self).setUp()
     course = self.course = CourseFactory.create(org="edX", course="999", display_name="Run 666")
     course2 = self.course2 = CourseFactory.create(org="edX", course="999a", display_name="Run 667")
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
     self.ccx2 = CcxFactory(course_id=course.id, coach=coach)
     self.ccx3 = CcxFactory(course_id=course.id, coach=coach)
     self.ccx4 = CcxFactory(course_id=course2.id, coach=coach)
Example #32
0
    def make_ccx(self):
        """
        create ccx
        """
        ccx = CustomCourseForEdX(course_id=self.course.id,
                                 coach=self.coach,
                                 display_name="Test CCX")
        ccx.save()

        ccx_locator = CCXLocator.from_course_locator(self.course.id,
                                                     unicode(ccx.id))
        role = CourseCcxCoachRole(ccx_locator)
        role.add_users(self.coach)
        CourseEnrollment.enroll(self.coach, ccx_locator)
        return ccx_locator
Example #33
0
    def setUp(self):
        super(TestGetEmailParamsCCX, self).setUp()
        self.coach = AdminFactory.create()
        role = CourseCcxCoachRole(self.course.id)
        role.add_users(self.coach)
        self.ccx = CcxFactory(course_id=self.course.id, coach=self.coach)
        self.course_key = CCXLocator.from_course_locator(
            self.course.id, self.ccx.id)

        # Explicitly construct what we expect the course URLs to be
        site = settings.SITE_NAME
        self.course_url = u'https://{}/courses/{}/'.format(
            site, self.course_key)
        self.course_about_url = self.course_url + 'about'
        self.registration_url = u'https://{}/register'.format(site)
 def setUp(self):
     """
     Set up tests
     """
     super(TestGetEmailParams, self).setUp()
     course = CourseFactory.create()
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
     self.all_keys = [
         'site_name', 'course', 'course_url', 'registration_url',
         'course_about_url', 'auto_enroll'
     ]
     self.url_keys = [k for k in self.all_keys if 'url' in k]
     self.course_keys = [k for k in self.url_keys if 'course' in k]
Example #35
0
    def test_create_ccx_with_ccx_connector_set(self):
        """
        Assert that coach cannot create ccx when ``ccx_connector`` url is set.
        """
        role = CourseCcxCoachRole(self.course_with_ccx_connect_set.id)
        role.add_users(self.coach)

        url = reverse(
            'create_ccx',
            kwargs={'course_id': unicode(self.course_with_ccx_connect_set.id)})

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        error_message = _(
            "A CCX can only be created on this course through an external service."
            " Contact a course admin to give you access."
        )
        self.assertTrue(re.search(error_message, response.content))
Example #36
0
 def setUp(self):
     """
     Set up tests
     """
     super(TestSendCCXCoursePublished, self).setUp()
     course = self.course = CourseFactory.create(org="edX",
                                                 course="999",
                                                 display_name="Run 666")
     course2 = self.course2 = CourseFactory.create(org="edX",
                                                   course="999a",
                                                   display_name="Run 667")
     coach = AdminFactory.create()
     role = CourseCcxCoachRole(course.id)
     role.add_users(coach)
     self.ccx = CcxFactory(course_id=course.id, coach=coach)
     self.ccx2 = CcxFactory(course_id=course.id, coach=coach)
     self.ccx3 = CcxFactory(course_id=course.id, coach=coach)
     self.ccx4 = CcxFactory(course_id=course2.id, coach=coach)
    def get_email_params_ccx(self):
        """
        Returns a dictionary of parameters used to render an email for CCX.
        """
        coach = AdminFactory.create()
        role = CourseCcxCoachRole(self.course.id)
        role.add_users(coach)
        self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
        self.course_key = CCXLocator.from_course_locator(
            self.course.id, self.ccx.id)

        email_params = get_email_params(self.course,
                                        True,
                                        course_key=self.course_key,
                                        display_name=self.ccx.display_name)
        email_params["email_address"] = "*****@*****.**"
        email_params["full_name"] = "Jean Reno"

        return email_params
Example #38
0
    def get_email_params_ccx(self):
        """
        Returns a dictionary of parameters used to render an email for CCX.
        """
        coach = AdminFactory.create()
        role = CourseCcxCoachRole(self.course.id)
        role.add_users(coach)
        self.ccx = CcxFactory(course_id=self.course.id, coach=coach)
        self.course_key = CCXLocator.from_course_locator(self.course.id, self.ccx.id)

        email_params = get_email_params(
            self.course,
            True,
            course_key=self.course_key,
            display_name=self.ccx.display_name
        )
        email_params["email_address"] = "*****@*****.**"
        email_params["full_name"] = "Jean Reno"

        return email_params
Example #39
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, self).setUp()

        # Create instructor account
        self.coach = coach = AdminFactory.create()
        self.client.login(username=coach.username, password="******")

        # Create CCX
        role = CourseCcxCoachRole(self._course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=self._course.id, coach=self.coach)

        # override course grading policy and make last section invisible to students
        override_field_for_ccx(
            ccx, self._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, self.sections[-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(self._course.id, ccx.id)
        self.course = get_course_by_id(self.ccx_key, depth=None)
        setup_students_and_grades(self)
        self.client.login(username=coach.username, password="******")
        self.addCleanup(RequestCache.clear_request_cache)
    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="******")
Example #41
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="******")
Example #42
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, self).setUp()

        self._course = CourseFactory.create(enable_ccx=True)

        # Create a course outline
        self.start = datetime.datetime(
            2010, 5, 12, 2, 42, tzinfo=pytz.UTC
        )
        chapter = ItemFactory.create(
            start=self.start, parent=self._course, category='sequential'
        )
        self.sections = [
            ItemFactory.create(
                parent=chapter,
                category="sequential",
                metadata={'graded': True, 'format': 'Homework'})
            for _ in xrange(4)
        ]
        # making problems available at class level for possible future use in tests
        self.problems = [
            [
                ItemFactory.create(
                    parent=section,
                    category="problem",
                    data=StringResponseXMLFactory().build_xml(answer='foo'),
                    metadata={'rerandomize': 'always'}
                ) for _ in xrange(4)
            ] for section in self.sections
        ]

        # Create instructor account
        self.coach = coach = AdminFactory.create()
        self.client.login(username=coach.username, password="******")

        # Create CCX
        role = CourseCcxCoachRole(self._course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=self._course.id, coach=self.coach)

        # override course grading policy and make last section invisible to students
        override_field_for_ccx(ccx, self._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, self.sections[-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(self._course.id, ccx.id)
        self.course = get_course_by_id(self.ccx_key, depth=None)
        setup_students_and_grades(self)
        self.client.login(username=coach.username, password="******")
        self.addCleanup(RequestCache.clear_request_cache)
Example #43
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, 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,
                                     category='sequential')
        sections = [
            ItemFactory.create(parent=chapter,
                               category="sequential",
                               metadata={
                                   'graded': True,
                                   'format': 'Homework'
                               }) for _ in xrange(4)
        ]
        # 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 sections]

        # Create CCX
        role = CourseCcxCoachRole(course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=course.id, coach=self.coach)

        # 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',
                    'weight': 1
                }],
                'GRADE_CUTOFFS': {
                    'Pass': 0.75
                },
            })
        override_field_for_ccx(ccx, sections[-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, section in enumerate(chapter.get_children()):
                for j, problem in enumerate(section.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="******")

        self.addCleanup(RequestCache.clear_request_cache)
Example #44
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, 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, category='sequential')
        sections = [
            ItemFactory.create(
                parent=chapter,
                category="sequential",
                metadata={'graded': True, 'format': 'Homework'})
            for _ in xrange(4)]
        # 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 sections
        ]

        # Create CCX
        role = CourseCcxCoachRole(course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=course.id, coach=self.coach)

        # 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',
                 'weight': 1}
            ],
            'GRADE_CUTOFFS': {'Pass': 0.75},
        })
        override_field_for_ccx(
            ccx, sections[-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)

        # create grades for self.student as if they'd submitted the ccx
        for chapter in self.course.get_children():
            for i, section in enumerate(chapter.get_children()):
                for j, problem in enumerate(section.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="******")

        self.addCleanup(RequestCache.clear_request_cache)
Example #45
0
    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)
Example #46
0
    def setUp(self):
        """
        Set up tests
        """
        super(TestCCXGrades, self).setUp()

        self._course = CourseFactory.create(enable_ccx=True)

        # Create a course outline
        self.start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC)
        chapter = ItemFactory.create(start=self.start,
                                     parent=self._course,
                                     category='sequential')
        self.sections = [
            ItemFactory.create(parent=chapter,
                               category="sequential",
                               metadata={
                                   'graded': True,
                                   'format': 'Homework'
                               }) for _ in xrange(4)
        ]
        # making problems available at class level for possible future use in tests
        self.problems = [[
            ItemFactory.create(
                parent=section,
                category="problem",
                data=StringResponseXMLFactory().build_xml(answer='foo'),
                metadata={'rerandomize': 'always'}) for _ in xrange(4)
        ] for section in self.sections]

        # Create instructor account
        self.coach = coach = AdminFactory.create()
        self.client.login(username=coach.username, password="******")

        # Create CCX
        role = CourseCcxCoachRole(self._course.id)
        role.add_users(coach)
        ccx = CcxFactory(course_id=self._course.id, coach=self.coach)

        # override course grading policy and make last section invisible to students
        override_field_for_ccx(
            ccx, self._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, self.sections[-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(self._course.id, ccx.id)
        self.course = get_course_by_id(self.ccx_key, depth=None)
        setup_students_and_grades(self)
        self.client.login(username=coach.username, password="******")
        self.addCleanup(RequestCache.clear_request_cache)
Example #47
0
 def make_coach(self):
     """
     create coach user
     """
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(self.coach)
 def make_coach(self):
     """
     create coach user
     """
     role = CourseCcxCoachRole(self.course.id)
     role.add_users(self.coach)
    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)