Beispiel #1
0
 def test_ccx_locator(self):
     """verify that the ccx is retuned if using a ccx locator
     """
     ccx = CcxFactory(course_id=self.course.id, coach=self.coach)
     course_key = CCXLocator.from_course_locator(self.course.id, ccx.id)
     result = self.call_fut(course_key)
     self.assertEqual(result, ccx)
 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)
Beispiel #3
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)
    def setup_course(self, size, enable_ccx):
        """
        Build a gradable course where each node has `size` children.
        """
        grading_policy = {
            "GRADER": [
                {
                    "drop_count": 2,
                    "min_count": 12,
                    "short_label": "HW",
                    "type": "Homework",
                    "weight": 0.15
                },
                {
                    "drop_count": 2,
                    "min_count": 12,
                    "type": "Lab",
                    "weight": 0.15
                },
                {
                    "drop_count": 0,
                    "min_count": 1,
                    "short_label": "Midterm",
                    "type": "Midterm Exam",
                    "weight": 0.3
                },
                {
                    "drop_count": 0,
                    "min_count": 1,
                    "short_label": "Final",
                    "type": "Final Exam",
                    "weight": 0.4
                }
            ],
            "GRADE_CUTOFFS": {
                "Pass": 0.5
            }
        }

        self.course = CourseFactory.create(
            graded=True,
            start=datetime.now(UTC),
            grading_policy=grading_policy,
            enable_ccx=enable_ccx,
        )
        self.populate_course(size)

        CourseEnrollment.enroll(
            self.student,
            self.course.id
        )

        if enable_ccx:
            self.ccx = CcxFactory.create()
            CcxMembershipFactory.create(
                student=self.student,
                ccx=self.ccx
            )
Beispiel #5
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 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()
Beispiel #7
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):
     """
     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)
Beispiel #9
0
    def setup_course(self, size, enable_ccx, view_as_ccx):
        """
        Build a gradable course where each node has `size` children.
        """
        grading_policy = {
            "GRADER": [{
                "drop_count": 2,
                "min_count": 12,
                "short_label": "HW",
                "type": "Homework",
                "weight": 0.15
            }, {
                "drop_count": 2,
                "min_count": 12,
                "type": "Lab",
                "weight": 0.15
            }, {
                "drop_count": 0,
                "min_count": 1,
                "short_label": "Midterm",
                "type": "Midterm Exam",
                "weight": 0.3
            }, {
                "drop_count": 0,
                "min_count": 1,
                "short_label": "Final",
                "type": "Final Exam",
                "weight": 0.4
            }],
            "GRADE_CUTOFFS": {
                "Pass": 0.5
            }
        }

        self.course = CourseFactory.create(
            graded=True,
            start=datetime.now(UTC),
            grading_policy=grading_policy,
            enable_ccx=enable_ccx,
        )
        self.populate_course(size)

        course_key = self.course.id
        if enable_ccx:
            self.ccx = CcxFactory.create(course_id=self.course.id)
            if view_as_ccx:
                course_key = CCXLocator.from_course_locator(
                    self.course.id, self.ccx.id)

        CourseEnrollment.enroll(self.student, course_key)
Beispiel #10
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]
Beispiel #12
0
    def test_has_staff_access_to_preview_mode(self):
        """
        Tests users have right access to content in preview mode.
        """
        course_key = self.course.id
        usage_key = self.course.scope_ids.usage_id
        chapter = ItemFactory.create(category="chapter",
                                     parent_location=self.course.location)
        overview = CourseOverview.get_from_id(course_key)
        test_system = get_test_system()

        ccx = CcxFactory(course_id=course_key)
        ccx_locator = CCXLocator.from_course_locator(course_key, ccx.id)

        error_descriptor = ErrorDescriptor.from_xml(
            u"<problem>ABC \N{SNOWMAN}</problem>", test_system,
            CourseLocationManager(course_key), "error msg")
        # Enroll student to the course
        CourseEnrollmentFactory(user=self.student, course_id=self.course.id)

        modules = [
            self.course,
            overview,
            chapter,
            ccx_locator,
            error_descriptor,
            course_key,
            usage_key,
        ]
        # Course key is not None
        self.assertTrue(
            bool(
                access.has_staff_access_to_preview_mode(
                    self.global_staff, obj=self.course,
                    course_key=course_key)))

        for user in [
                self.global_staff, self.course_staff, self.course_instructor
        ]:
            for obj in modules:
                self.assertTrue(
                    bool(access.has_staff_access_to_preview_mode(user,
                                                                 obj=obj)))
                self.assertFalse(
                    bool(
                        access.has_staff_access_to_preview_mode(self.student,
                                                                obj=obj)))
    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
Beispiel #14
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="******")