Example #1
0
    def test_course_tabs_staff_only(self):
        """
        Tests the static tabs that available only for instructor
        """
        self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Free',
                                                            url_slug='extra_tab_1',
                                                            course_staff_only=False))
        self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Instructors Only',
                                                            url_slug='extra_tab_2',
                                                            course_staff_only=True))
        self.course.save()

        user = self.create_mock_user(is_authenticated=True, is_staff=False, is_enrolled=True)
        request = get_request_for_user(user)
        course_tab_list = get_course_tab_list(request, self.course)
        name_list = [x.name for x in course_tab_list]
        self.assertIn('Static Tab Free', name_list)
        self.assertNotIn('Static Tab Instructors Only', name_list)

        # Login as member of staff
        self.client.logout()
        staff_user = StaffFactory(course_key=self.course.id)
        self.client.login(username=staff_user.username, password='******')
        request = get_request_for_user(staff_user)
        course_tab_list_staff = get_course_tab_list(request, self.course)
        name_list_staff = [x.name for x in course_tab_list_staff]
        self.assertIn('Static Tab Free', name_list_staff)
        self.assertIn('Static Tab Instructors Only', name_list_staff)
Example #2
0
        def test_get_course_tabs_list_skipped_entrance_exam(self):
            """
            Tests tab list is not limited if user is allowed to skip entrance exam.
            """
            #create a user
            student = UserFactory()
            # login as instructor hit skip entrance exam api in instructor app
            instructor = InstructorFactory(course_key=self.course.id)
            self.client.logout()
            self.client.login(username=instructor.username, password='******')

            url = reverse('mark_student_can_skip_entrance_exam',
                          kwargs={'course_id': unicode(self.course.id)})
            response = self.client.post(
                url, {
                    'unique_student_identifier': student.email,
                })
            self.assertEqual(response.status_code, 200)

            # log in again as student
            self.client.logout()
            self.login(self.email, self.password)
            request = get_request_for_user(self.user)
            course_tab_list = get_course_tab_list(request, self.course)
            self.assertEqual(len(course_tab_list), 5)
 def setUpClass(cls):
     super(TestStudentModuleGrading, cls).setUpClass()
     cls.course = CourseFactory.create()
     cls.chapter = ItemFactory.create(
         parent=cls.course,
         category="chapter",
         display_name="Test Chapter"
     )
     cls.sequence = ItemFactory.create(
         parent=cls.chapter,
         category='sequential',
         display_name="Test Sequential 1",
         graded=True
     )
     cls.vertical = ItemFactory.create(
         parent=cls.sequence,
         category='vertical',
         display_name='Test Vertical 1'
     )
     problem_xml = MultipleChoiceResponseXMLFactory().build_xml(
         question_text='The correct answer is Choice 3',
         choices=[False, False, True, False],
         choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3']
     )
     cls.problem = ItemFactory.create(
         parent=cls.vertical,
         category="problem",
         display_name="Test Problem",
         data=problem_xml
     )
     cls.request = get_request_for_user(UserFactory())
     cls.user = cls.request.user
Example #4
0
 def setUpClass(cls):
     super(TestStudentModuleGrading, cls).setUpClass()
     cls.course = CourseFactory.create()
     cls.chapter = ItemFactory.create(
         parent=cls.course,
         category="chapter",
         display_name="Test Chapter"
     )
     cls.sequence = ItemFactory.create(
         parent=cls.chapter,
         category='sequential',
         display_name="Test Sequential 1",
         graded=True
     )
     cls.vertical = ItemFactory.create(
         parent=cls.sequence,
         category='vertical',
         display_name='Test Vertical 1'
     )
     problem_xml = MultipleChoiceResponseXMLFactory().build_xml(
         question_text='The correct answer is Choice 3',
         choices=[False, False, True, False],
         choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3']
     )
     cls.problem = ItemFactory.create(
         parent=cls.vertical,
         category="problem",
         display_name="Test Problem",
         data=problem_xml
     )
     cls.request = get_request_for_user(UserFactory())
     cls.user = cls.request.user
Example #5
0
 def test_get_course_tabs_list_entrance_exam_enabled(self):
     """
     Unit Test: test_get_course_tabs_list_entrance_exam_enabled
     """
     entrance_exam = ItemFactory.create(
         category="chapter",
         parent_location=self.course.location,
         data="Exam Data",
         display_name="Entrance Exam",
         is_entrance_exam=True)
     milestone = {
         'name': 'Test Milestone',
         'namespace':
         '{}.entrance_exams'.format(unicode(self.course.id)),
         'description': 'Testing Courseware Tabs'
     }
     self.user.is_staff = False
     request = get_request_for_user(self.user)
     self.course.entrance_exam_enabled = True
     self.course.entrance_exam_id = unicode(entrance_exam.location)
     milestone = milestones_helpers.add_milestone(milestone)
     milestones_helpers.add_course_milestone(
         unicode(self.course.id), self.relationship_types['REQUIRES'],
         milestone)
     milestones_helpers.add_course_content_milestone(
         unicode(self.course.id), unicode(entrance_exam.location),
         self.relationship_types['FULFILLS'], milestone)
     course_tab_list = get_course_tab_list(request, self.course)
     self.assertEqual(len(course_tab_list), 1)
     self.assertEqual(course_tab_list[0]['tab_id'], 'courseware')
     self.assertEqual(course_tab_list[0]['name'], 'Entrance Exam')
 def test_get_course_tabs_list_entrance_exam_enabled(self):
     """
     Unit Test: test_get_course_tabs_list_entrance_exam_enabled
     """
     entrance_exam = ItemFactory.create(
         category="chapter",
         parent_location=self.course.location,
         data="Exam Data",
         display_name="Entrance Exam",
         is_entrance_exam=True,
     )
     milestone = {
         "name": "Test Milestone",
         "namespace": "{}.entrance_exams".format(unicode(self.course.id)),
         "description": "Testing Courseware Tabs",
     }
     self.user.is_staff = False
     request = get_request_for_user(self.user)
     self.course.entrance_exam_enabled = True
     self.course.entrance_exam_id = unicode(entrance_exam.location)
     milestone = milestones_helpers.add_milestone(milestone)
     milestones_helpers.add_course_milestone(
         unicode(self.course.id), self.relationship_types["REQUIRES"], milestone
     )
     milestones_helpers.add_course_content_milestone(
         unicode(self.course.id), unicode(entrance_exam.location), self.relationship_types["FULFILLS"], milestone
     )
     course_tab_list = get_course_tab_list(request, self.course)
     self.assertEqual(len(course_tab_list), 1)
     self.assertEqual(course_tab_list[0]["tab_id"], "courseware")
     self.assertEqual(course_tab_list[0]["name"], "Entrance Exam")
Example #7
0
 def setUp(self):
     super(TestMultipleProblemTypesSubsectionScores, self).setUp()
     password = u'test'
     self.student = UserFactory.create(is_staff=False, username=u'test_student', password=password)
     self.client.login(username=self.student.username, password=password)
     self.request = get_request_for_user(self.student)
     self.course = CourseFactory.create(
         display_name=self.COURSE_NAME,
         number=self.COURSE_NUM
     )
     self.chapter = ItemFactory.create(
         parent=self.course,
         category=u'chapter',
         display_name=u'Test Chapter'
     )
     self.seq1 = ItemFactory.create(
         parent=self.chapter,
         category=u'sequential',
         display_name=u'Test Sequential 1',
         graded=True
     )
     self.vert1 = ItemFactory.create(
         parent=self.seq1,
         category=u'vertical',
         display_name=u'Test Vertical 1'
     )
Example #8
0
 def setUp(self):
     super(GradeTestBase, self).setUp()
     self.request = get_request_for_user(UserFactory())
     self.client.login(username=self.request.user.username, password="******")
     self.course_structure = get_course_blocks(self.request.user, self.course.location)
     self.subsection_grade_factory = SubsectionGradeFactory(self.request.user, self.course, self.course_structure)
     CourseEnrollment.enroll(self.request.user, self.course.id)
Example #9
0
    def setUpClass(cls):
        super(TestScoreForModule, cls).setUpClass()
        cls.course = CourseFactory.create()
        cls.a = ItemFactory.create(parent=cls.course, category="chapter", display_name="a")
        cls.b = ItemFactory.create(parent=cls.a, category="sequential", display_name="b")
        cls.c = ItemFactory.create(parent=cls.a, category="sequential", display_name="c")
        cls.d = ItemFactory.create(parent=cls.b, category="vertical", display_name="d")
        cls.e = ItemFactory.create(parent=cls.b, category="vertical", display_name="e")
        cls.f = ItemFactory.create(parent=cls.b, category="vertical", display_name="f")
        cls.g = ItemFactory.create(parent=cls.c, category="vertical", display_name="g")
        cls.h = ItemFactory.create(parent=cls.d, category="problem", display_name="h")
        cls.i = ItemFactory.create(parent=cls.d, category="problem", display_name="i")
        cls.j = ItemFactory.create(parent=cls.e, category="problem", display_name="j")
        cls.k = ItemFactory.create(parent=cls.e, category="html", display_name="k")
        cls.l = ItemFactory.create(parent=cls.e, category="problem", display_name="l")
        cls.m = ItemFactory.create(parent=cls.f, category="html", display_name="m")
        cls.n = ItemFactory.create(parent=cls.g, category="problem", display_name="n")

        cls.request = get_request_for_user(UserFactory())
        CourseEnrollment.enroll(cls.request.user, cls.course.id)

        answer_problem(cls.course, cls.request, cls.h, score=2, max_value=5)
        answer_problem(cls.course, cls.request, cls.i, score=3, max_value=5)
        answer_problem(cls.course, cls.request, cls.j, score=0, max_value=1)
        answer_problem(cls.course, cls.request, cls.l, score=1, max_value=3)
        answer_problem(cls.course, cls.request, cls.n, score=3, max_value=10)

        cls.course_grade = CourseGradeFactory(cls.request.user).create(cls.course)
Example #10
0
 def setUp(self):
     super(TestVariedMetadata, self).setUp()
     self.course = CourseFactory.create()
     self.chapter = ItemFactory.create(parent=self.course,
                                       category="chapter",
                                       display_name="Test Chapter")
     self.sequence = ItemFactory.create(parent=self.chapter,
                                        category='sequential',
                                        display_name="Test Sequential 1",
                                        graded=True)
     self.vertical = ItemFactory.create(parent=self.sequence,
                                        category='vertical',
                                        display_name='Test Vertical 1')
     self.problem_xml = u'''
         <problem url_name="capa-optionresponse">
           <optionresponse>
             <optioninput options="('Correct', 'Incorrect')" correct="Correct"></optioninput>
             <optioninput options="('Correct', 'Incorrect')" correct="Correct"></optioninput>
           </optionresponse>
         </problem>
     '''
     self.request = get_request_for_user(UserFactory())
     self.client.login(username=self.request.user.username, password="******")
     CourseEnrollment.enroll(self.request.user, self.course.id)
     course_structure = get_course_blocks(self.request.user,
                                          self.course.location)
     self.subsection_factory = SubsectionGradeFactory(
         self.request.user,
         course_structure=course_structure,
         course=self.course,
     )
Example #11
0
    def setUpClass(cls):
        super(TestScoreForModule, cls).setUpClass()
        cls.course = CourseFactory.create()
        cls.a = ItemFactory.create(parent=cls.course, category="chapter", display_name="a")
        cls.b = ItemFactory.create(parent=cls.a, category="sequential", display_name="b")
        cls.c = ItemFactory.create(parent=cls.a, category="sequential", display_name="c")
        cls.d = ItemFactory.create(parent=cls.b, category="vertical", display_name="d")
        cls.e = ItemFactory.create(parent=cls.b, category="vertical", display_name="e")
        cls.f = ItemFactory.create(parent=cls.b, category="vertical", display_name="f")
        cls.g = ItemFactory.create(parent=cls.c, category="vertical", display_name="g")
        cls.h = ItemFactory.create(parent=cls.d, category="problem", display_name="h")
        cls.i = ItemFactory.create(parent=cls.d, category="problem", display_name="i")
        cls.j = ItemFactory.create(parent=cls.e, category="problem", display_name="j")
        cls.k = ItemFactory.create(parent=cls.e, category="html", display_name="k")
        cls.l = ItemFactory.create(parent=cls.e, category="problem", display_name="l")
        cls.m = ItemFactory.create(parent=cls.f, category="html", display_name="m")
        cls.n = ItemFactory.create(parent=cls.g, category="problem", display_name="n")

        cls.request = get_request_for_user(UserFactory())
        CourseEnrollment.enroll(cls.request.user, cls.course.id)

        answer_problem(cls.course, cls.request, cls.h, score=2, max_value=5)
        answer_problem(cls.course, cls.request, cls.i, score=3, max_value=5)
        answer_problem(cls.course, cls.request, cls.j, score=0, max_value=1)
        answer_problem(cls.course, cls.request, cls.l, score=1, max_value=3)
        answer_problem(cls.course, cls.request, cls.n, score=3, max_value=10)

        cls.course_grade = CourseGradeFactory(cls.request.user).create(cls.course)
Example #12
0
 def setUp(self):
     super(TestMultipleProblemTypesSubsectionScores, self).setUp()
     password = u'test'
     self.student = UserFactory.create(is_staff=False, username=u'test_student', password=password)
     self.client.login(username=self.student.username, password=password)
     self.request = get_request_for_user(self.student)
     self.course = CourseFactory.create(
         display_name=self.COURSE_NAME,
         number=self.COURSE_NUM
     )
     self.chapter = ItemFactory.create(
         parent=self.course,
         category=u'chapter',
         display_name=u'Test Chapter'
     )
     self.seq1 = ItemFactory.create(
         parent=self.chapter,
         category=u'sequential',
         display_name=u'Test Sequential 1',
         graded=True
     )
     self.vert1 = ItemFactory.create(
         parent=self.seq1,
         category=u'vertical',
         display_name=u'Test Vertical 1'
     )
Example #13
0
 def setUp(self):
     super(GradeTestBase, self).setUp()
     self.request = get_request_for_user(UserFactory())
     self.client.login(username=self.request.user.username, password="******")
     self.subsection_grade_factory = SubsectionGradeFactory(self.request.user)
     self.course_structure = get_course_blocks(self.request.user, self.course.location)
     CourseEnrollment.enroll(self.request.user, self.course.id)
Example #14
0
 def setUp(self):
     """
     Set up test course
     """
     super(TestCourseGradeFactory, self).setUp()
     self.request = get_request_for_user(UserFactory())
     self.client.login(username=self.request.user.username, password="******")
     CourseEnrollment.enroll(self.request.user, self.course.id)
Example #15
0
 def setUp(self):
     """
     Set up test course
     """
     super(TestCourseGradeFactory, self).setUp()
     self.request = get_request_for_user(UserFactory())
     self.client.login(username=self.request.user.username, password="******")
     CourseEnrollment.enroll(self.request.user, self.course.id)
Example #16
0
 def _create_mock_json_request(self, user, body, method='POST', session=None):
     """
     Returns a mock JSON request for the specified user
     """
     request = get_request_for_user(user)
     request.method = method
     request.META = {'CONTENT_TYPE': ['application/json']}
     request.body = body
     request.session = session or {}
     return request
Example #17
0
 def setUp(self):
     super(TestMultipleProblemTypesSubsectionScores, self).setUp()
     password = u'test'
     self.student = UserFactory.create(is_staff=False,
                                       username=u'test_student',
                                       password=password)
     self.client.login(username=self.student.username, password=password)
     self.request = get_request_for_user(self.student)
     self.course_structure = get_course_blocks(self.student,
                                               self.course.location)
Example #18
0
 def _create_mock_json_request(self, user, body, method='POST', session=None):
     """
     Returns a mock JSON request for the specified user
     """
     request = get_request_for_user(user)
     request.method = method
     request.META = {'CONTENT_TYPE': ['application/json']}
     request.body = body
     request.session = session or {}
     return request
    def setUp(self):
        """
        Set up the course and user context
        """
        super(CoursesRenderTest, self).setUp()

        store = modulestore()
        course_items = import_course_from_xml(store, self.user.id, TEST_DATA_DIR, ['toy'])
        course_key = course_items[0].id
        self.course = get_course_by_id(course_key)
        self.request = get_request_for_user(UserFactory.create())
    def setUp(self):
        """
        Set up the course and user context
        """
        super(CoursesRenderTest, self).setUp()

        store = modulestore()
        course_items = import_course_from_xml(store, self.user.id, TEST_DATA_DIR, ['toy'])
        course_key = course_items[0].id
        self.course = get_course_by_id(course_key)
        self.request = get_request_for_user(UserFactory.create())
Example #21
0
    def setUp(self):
        """
        Set up test course
        """
        super(TestGetModuleScore, self).setUp()

        self.request = get_request_for_user(UserFactory())
        self.client.login(username=self.request.user.username, password="******")
        CourseEnrollment.enroll(self.request.user, self.course.id)

        # warm up the score cache to allow accurate query counts, even if tests are run in random order
        get_module_score(self.request.user, self.course, self.seq1)
Example #22
0
 def setUp(self):
     super(XapiTest, self).setUp()
     self.tracker = DjangoTracker()
     tracker.register_tracker(self.tracker)
     user = UserFactory.create(username=TEST_USERNAME)
     UserSocialAuth.objects.create(user=user, provider="eco", uid=TEST_UID)
     self.user = user
     self.request = get_request_for_user(user)
     fields = dict(XAPI_BACKEND_CONFIG)
     XapiBackendConfig(**fields).save()
     self.backend = XapiBackend()
     self.tincanwrapper = TinCanWrapper()
Example #23
0
 def test_course_tabs_list_for_staff_members(self):
     """
     Tests tab list is not limited if user is member of staff
     and has not passed entrance exam.
     """
     # Login as member of staff
     self.client.logout()
     staff_user = StaffFactory(course_key=self.course.id)
     self.client.login(username=staff_user.username, password='******')
     request = get_request_for_user(staff_user)
     course_tab_list = get_course_tab_list(request, self.course)
     self.assertEqual(len(course_tab_list), 5)
Example #24
0
    def setUp(self):
        """
        Set up test course
        """
        super(TestGetModuleScore, self).setUp()

        self.request = get_request_for_user(UserFactory())
        self.client.login(username=self.request.user.username, password="******")
        CourseEnrollment.enroll(self.request.user, self.course.id)

        # warm up the score cache to allow accurate query counts, even if tests are run in random order
        get_module_score(self.request.user, self.course, self.seq1)
Example #25
0
 def test_course_tabs_list_for_staff_members(self):
     """
     Tests tab list is not limited if user is member of staff
     and has not passed entrance exam.
     """
     # Login as member of staff
     self.client.logout()
     staff_user = StaffFactory(course_key=self.course.id)
     self.client.login(username=staff_user.username, password='******')
     request = get_request_for_user(staff_user)
     course_tab_list = get_course_tab_list(request, self.course)
     self.assertEqual(len(course_tab_list), 5)
Example #26
0
    def setUp(self):
        """
        Set up test course
        """
        super(TestGetModuleScore, self).setUp()
        self.course = CourseFactory.create()
        self.chapter = ItemFactory.create(parent=self.course,
                                          category="chapter",
                                          display_name="Test Chapter")
        self.seq1 = ItemFactory.create(parent=self.chapter,
                                       category='sequential',
                                       display_name="Test Sequential",
                                       graded=True)
        self.seq2 = ItemFactory.create(parent=self.chapter,
                                       category='sequential',
                                       display_name="Test Sequential",
                                       graded=True)
        self.vert1 = ItemFactory.create(parent=self.seq1,
                                        category='vertical',
                                        display_name='Test Vertical 1')
        self.vert2 = ItemFactory.create(parent=self.seq2,
                                        category='vertical',
                                        display_name='Test Vertical 2')
        self.randomize = ItemFactory.create(parent=self.vert2,
                                            category='randomize',
                                            display_name='Test Randomize')
        problem_xml = MultipleChoiceResponseXMLFactory().build_xml(
            question_text='The correct answer is Choice 3',
            choices=[False, False, True, False],
            choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'])
        self.problem1 = ItemFactory.create(parent=self.vert1,
                                           category="problem",
                                           display_name="Test Problem 1",
                                           data=problem_xml)
        self.problem2 = ItemFactory.create(parent=self.vert1,
                                           category="problem",
                                           display_name="Test Problem 2",
                                           data=problem_xml)
        self.problem3 = ItemFactory.create(parent=self.randomize,
                                           category="problem",
                                           display_name="Test Problem 3",
                                           data=problem_xml)
        self.problem4 = ItemFactory.create(parent=self.randomize,
                                           category="problem",
                                           display_name="Test Problem 4",
                                           data=problem_xml)

        self.request = get_request_for_user(UserFactory())
        self.client.login(username=self.request.user.username, password="******")
        CourseEnrollment.enroll(self.request.user, self.course.id)
Example #27
0
 def setUp(self):
     super(TestCourseGradeLogging, self).setUp()
     self.course = CourseFactory.create()
     self.chapter = ItemFactory.create(parent=self.course,
                                       category="chapter",
                                       display_name="Test Chapter")
     self.sequence = ItemFactory.create(parent=self.chapter,
                                        category='sequential',
                                        display_name="Test Sequential 1",
                                        graded=True)
     self.sequence_2 = ItemFactory.create(parent=self.chapter,
                                          category='sequential',
                                          display_name="Test Sequential 2",
                                          graded=True)
     self.sequence_3 = ItemFactory.create(parent=self.chapter,
                                          category='sequential',
                                          display_name="Test Sequential 3",
                                          graded=False)
     self.vertical = ItemFactory.create(parent=self.sequence,
                                        category='vertical',
                                        display_name='Test Vertical 1')
     self.vertical_2 = ItemFactory.create(parent=self.sequence_2,
                                          category='vertical',
                                          display_name='Test Vertical 2')
     self.vertical_3 = ItemFactory.create(parent=self.sequence_3,
                                          category='vertical',
                                          display_name='Test Vertical 3')
     problem_xml = MultipleChoiceResponseXMLFactory().build_xml(
         question_text='The correct answer is Choice 2',
         choices=[False, False, True, False],
         choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3'])
     self.problem = ItemFactory.create(parent=self.vertical,
                                       category="problem",
                                       display_name="test_problem_1",
                                       data=problem_xml)
     self.problem_2 = ItemFactory.create(parent=self.vertical_2,
                                         category="problem",
                                         display_name="test_problem_2",
                                         data=problem_xml)
     self.problem_3 = ItemFactory.create(parent=self.vertical_3,
                                         category="problem",
                                         display_name="test_problem_3",
                                         data=problem_xml)
     self.request = get_request_for_user(UserFactory())
     self.client.login(username=self.request.user.username, password="******")
     self.course_structure = get_course_blocks(self.request.user,
                                               self.course.location)
     self.subsection_grade_factory = SubsectionGradeFactory(
         self.request.user, self.course, self.course_structure)
     CourseEnrollment.enroll(self.request.user, self.course.id)
Example #28
0
    def test_get_static_tab_contents(self):
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(UserFactory.create())
        tab = tabs.CourseTabList.get_tab_by_slug(course.tabs, "resources")

        # Test render works okay
        tab_content = get_static_tab_contents(request, course, tab)
        self.assertIn(self.toy_course_key.to_deprecated_string(), tab_content)
        self.assertIn("static_tab", tab_content)

        # Test when render raises an exception
        with patch("courseware.views.get_module") as mock_module_render:
            mock_module_render.return_value = MagicMock(render=Mock(side_effect=Exception("Render failed!")))
            static_tab = get_static_tab_contents(request, course, tab)
            self.assertIn("this module is temporarily unavailable", static_tab)
Example #29
0
    def test_get_course_info_section_render(self):
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(UserFactory.create())

        # Test render works okay
        course_info = get_course_info_section(request, course, 'handouts')
        self.assertEqual(course_info, "<a href='/static/toy/handouts/sample_handout.txt'>Sample</a>")

        # Test when render raises an exception
        with mock.patch('courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_info = get_course_info_section(request, course, 'handouts')
            self.assertIn("this module is temporarily unavailable", course_info)
    def test_get_course_info_section_render(self):
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(UserFactory.create())

        # Test render works okay. Note the href is different in XML courses.
        course_info = get_course_info_section(request, course, 'handouts')
        self.assertEqual(course_info, "<a href='/static/toy/handouts/sample_handout.txt'>Sample</a>")

        # Test when render raises an exception
        with mock.patch('courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_info = get_course_info_section(request, course, 'handouts')
            self.assertIn("this module is temporarily unavailable", course_info)
Example #31
0
    def test_get_course_about_section_render(self, mock_get_request):
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(UserFactory.create())
        mock_get_request.return_value = request

        # Test render works okay
        course_about = get_course_about_section(course, 'short_description')
        self.assertEqual(course_about, "A course about toys.")

        # Test when render raises an exception
        with mock.patch('courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_about = get_course_about_section(course, 'short_description')
            self.assertIn("this module is temporarily unavailable", course_about)
Example #32
0
    def test_get_static_tab_contents(self):
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(UserFactory.create())
        tab = CourseTabList.get_tab_by_slug(course.tabs, 'resources')

        # Test render works okay
        tab_content = get_static_tab_contents(request, course, tab)
        self.assertIn(self.toy_course_key.to_deprecated_string(), tab_content)
        self.assertIn('static_tab', tab_content)

        # Test when render raises an exception
        with patch('courseware.views.get_module') as mock_module_render:
            mock_module_render.return_value = MagicMock(render=Mock(
                side_effect=Exception('Render failed!')))
            static_tab = get_static_tab_contents(request, course, tab)
            self.assertIn("this module is temporarily unavailable", static_tab)
Example #33
0
    def test_get_course_about_section_render(self, mock_get_request):
        course = get_course_by_id('edX/toy/2012_Fall')
        request = get_request_for_user(UserFactory.create())
        mock_get_request.return_value = request

        # Test render works okay
        course_about = get_course_about_section(course, 'short_description')
        self.assertEqual(course_about, "A course about toys.")

        # Test when render raises an exception
        with mock.patch('courseware.courses.get_module') as mock_module_render:
            mock_module_render.return_value = mock.MagicMock(
                render=mock.Mock(side_effect=Exception('Render failed!'))
            )
            course_about = get_course_about_section(course, 'short_description')
            self.assertIn("this module is temporarily unavailable", course_about)
Example #34
0
    def test_get_static_tab_contents(self):
        course = get_course_by_id('edX/toy/2012_Fall')
        request = get_request_for_user(UserFactory.create())
        tab = CourseTabList.get_tab_by_slug(course, 'resources')

        # Test render works okay
        tab_content = get_static_tab_contents(request, course, tab)
        self.assertIn('edX/toy/2012_Fall', tab_content)
        self.assertIn('static_tab', tab_content)

        # Test when render raises an exception
        with patch('courseware.views.get_module') as mock_module_render:
            mock_module_render.return_value = MagicMock(
                render=Mock(side_effect=Exception('Render failed!'))
            )
            static_tab = get_static_tab_contents(request, course, tab)
            self.assertIn("this module is temporarily unavailable", static_tab)
Example #35
0
    def test_get_static_tab_contents(self):
        self.setup_user()
        course = get_course_by_id(self.toy_course_key)
        request = get_request_for_user(self.user)
        tab = xmodule_tabs.CourseTabList.get_tab_by_slug(course.tabs, 'resources')

        # Test render works okay
        tab_content = get_static_tab_contents(request, course, tab)
        self.assertIn(self.toy_course_key.to_deprecated_string(), tab_content)
        self.assertIn('static_tab', tab_content)

        # Test when render raises an exception
        with patch('courseware.views.get_module') as mock_module_render:
            mock_module_render.return_value = MagicMock(
                render=Mock(side_effect=Exception('Render failed!'))
            )
            static_tab = get_static_tab_contents(request, course, tab)
            self.assertIn("this module is temporarily unavailable", static_tab)
 def test_pdf_textbook_tabs(self):
     """
     Test that all textbooks tab links generating correctly.
     """
     type_to_reverse_name = {"textbook": "book", "pdftextbook": "pdf_book", "htmltextbook": "html_book"}
     request = get_request_for_user(self.user)
     course_tab_list = get_course_tab_list(request, self.course)
     num_of_textbooks_found = 0
     for tab in course_tab_list:
         # Verify links of all textbook type tabs.
         if tab.type == "single_textbook":
             book_type, book_index = tab.tab_id.split("/", 1)
             expected_link = reverse(
                 type_to_reverse_name[book_type], args=[self.course.id.to_deprecated_string(), book_index]
             )
             tab_link = tab.link_func(self.course, reverse)
             self.assertEqual(tab_link, expected_link)
             num_of_textbooks_found += 1
     self.assertEqual(num_of_textbooks_found, self.num_textbooks)
Example #37
0
 def test_pdf_textbook_tabs(self):
     """
     Test that all textbooks tab links generating correctly.
     """
     type_to_reverse_name = {'textbook': 'book', 'pdftextbook': 'pdf_book', 'htmltextbook': 'html_book'}
     request = get_request_for_user(self.user)
     course_tab_list = get_course_tab_list(request, self.course)
     num_of_textbooks_found = 0
     for tab in course_tab_list:
         # Verify links of all textbook type tabs.
         if tab.type == 'single_textbook':
             book_type, book_index = tab.tab_id.split("/", 1)
             expected_link = reverse(
                 type_to_reverse_name[book_type],
                 args=[self.course.id.to_deprecated_string(), book_index]
             )
             tab_link = tab.link_func(self.course, reverse)
             self.assertEqual(tab_link, expected_link)
             num_of_textbooks_found += 1
     self.assertEqual(num_of_textbooks_found, self.num_textbooks)
        def test_get_course_tabs_list_skipped_entrance_exam(self):
            """
            Tests tab list is not limited if user is allowed to skip entrance exam.
            """
            # create a user
            student = UserFactory()
            # login as instructor hit skip entrance exam api in instructor app
            instructor = InstructorFactory(course_key=self.course.id)
            self.client.logout()
            self.client.login(username=instructor.username, password="******")

            url = reverse("mark_student_can_skip_entrance_exam", kwargs={"course_id": unicode(self.course.id)})
            response = self.client.post(url, {"unique_student_identifier": student.email})
            self.assertEqual(response.status_code, 200)

            # log in again as student
            self.client.logout()
            self.login(self.email, self.password)
            request = get_request_for_user(self.user)
            course_tab_list = get_course_tab_list(request, self.course)
            self.assertEqual(len(course_tab_list), 5)
Example #39
0
 def test_get_course_tabs_list_entrance_exam_enabled(self):
     """
     Unit Test: test_get_course_tabs_list_entrance_exam_enabled
     """
     entrance_exam = ItemFactory.create(
         category="chapter",
         parent_location=self.course.location,
         data="Exam Data",
         display_name="Entrance Exam",
         is_entrance_exam=True
     )
     milestone = {
         'name': 'Test Milestone',
         'namespace': '{}.entrance_exams'.format(unicode(self.course.id)),
         'description': 'Testing Courseware Tabs'
     }
     self.user.is_staff = False
     request = get_request_for_user(self.user)
     self.course.entrance_exam_enabled = True
     self.course.entrance_exam_id = unicode(entrance_exam.location)
     milestone = add_milestone(milestone)
     add_course_milestone(
         unicode(self.course.id),
         self.relationship_types['REQUIRES'],
         milestone
     )
     add_course_content_milestone(
         unicode(self.course.id),
         unicode(entrance_exam.location),
         self.relationship_types['FULFILLS'],
         milestone
     )
     course_tab_list = get_course_tab_list(request, self.course)
     self.assertEqual(len(course_tab_list), 1)
     self.assertEqual(course_tab_list[0]['tab_id'], 'courseware')
     self.assertEqual(course_tab_list[0]['name'], 'Entrance Exam')
Example #40
0
 def test_invalid_course_key(self):
     self.setup_user()
     request = get_request_for_user(self.user)
     with self.assertRaises(Http404):
         static_tab(request, course_id='edX/toy', tab_slug='new_tab')
Example #41
0
 def test_invalid_course_key(self):
     request = get_request_for_user(UserFactory.create())
     with self.assertRaises(Http404):
         static_tab(request, course_id='edX/toy', tab_slug='new_tab')
Example #42
0
    def setUp(self):
        """
        Set up test course
        """
        super(TestGetModuleScore, self).setUp()
        self.course = CourseFactory.create()
        self.chapter = ItemFactory.create(
            parent=self.course,
            category="chapter",
            display_name="Test Chapter"
        )
        self.seq1 = ItemFactory.create(
            parent=self.chapter,
            category='sequential',
            display_name="Test Sequential",
            graded=True
        )
        self.seq2 = ItemFactory.create(
            parent=self.chapter,
            category='sequential',
            display_name="Test Sequential",
            graded=True
        )
        self.vert1 = ItemFactory.create(
            parent=self.seq1,
            category='vertical',
            display_name='Test Vertical 1'
        )
        self.vert2 = ItemFactory.create(
            parent=self.seq2,
            category='vertical',
            display_name='Test Vertical 2'
        )
        self.randomize = ItemFactory.create(
            parent=self.vert2,
            category='randomize',
            display_name='Test Randomize'
        )
        problem_xml = MultipleChoiceResponseXMLFactory().build_xml(
            question_text='The correct answer is Choice 3',
            choices=[False, False, True, False],
            choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3']
        )
        self.problem1 = ItemFactory.create(
            parent=self.vert1,
            category="problem",
            display_name="Test Problem 1",
            data=problem_xml
        )
        self.problem2 = ItemFactory.create(
            parent=self.vert1,
            category="problem",
            display_name="Test Problem 2",
            data=problem_xml
        )
        self.problem3 = ItemFactory.create(
            parent=self.randomize,
            category="problem",
            display_name="Test Problem 3",
            data=problem_xml
        )
        self.problem4 = ItemFactory.create(
            parent=self.randomize,
            category="problem",
            display_name="Test Problem 4",
            data=problem_xml
        )

        self.request = get_request_for_user(UserFactory())
        self.client.login(username=self.request.user.username, password="******")
        CourseEnrollment.enroll(self.request.user, self.course.id)
    def setUp(self):
        """
        Test case scaffolding
        """
        super(EntranceExamTestCases, self).setUp()
        self.course = CourseFactory.create(metadata={"entrance_exam_enabled": True})
        self.chapter = ItemFactory.create(parent=self.course, display_name="Overview")
        ItemFactory.create(parent=self.chapter, display_name="Welcome")
        ItemFactory.create(parent=self.course, category="chapter", display_name="Week 1")
        self.chapter_subsection = ItemFactory.create(
            parent=self.chapter, category="sequential", display_name="Lesson 1"
        )
        chapter_vertical = ItemFactory.create(
            parent=self.chapter_subsection, category="vertical", display_name="Lesson 1 Vertical - Unit 1"
        )
        ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 1")
        ItemFactory.create(parent=chapter_vertical, category="problem", display_name="Problem - Unit 1 Problem 2")

        ItemFactory.create(category="instructor", parent=self.course, data="Instructor Tab", display_name="Instructor")
        self.entrance_exam = ItemFactory.create(
            parent=self.course,
            category="chapter",
            display_name="Entrance Exam Section - Chapter 1",
            is_entrance_exam=True,
            in_entrance_exam=True,
        )
        self.exam_1 = ItemFactory.create(
            parent=self.entrance_exam,
            category="sequential",
            display_name="Exam Sequential - Subsection 1",
            graded=True,
            in_entrance_exam=True,
        )
        subsection = ItemFactory.create(parent=self.exam_1, category="vertical", display_name="Exam Vertical - Unit 1")
        self.problem_1 = ItemFactory.create(
            parent=subsection, category="problem", display_name="Exam Problem - Problem 1"
        )
        self.problem_2 = ItemFactory.create(
            parent=subsection, category="problem", display_name="Exam Problem - Problem 2"
        )

        seed_milestone_relationship_types()
        add_entrance_exam_milestone(self.course, self.entrance_exam)

        self.course.entrance_exam_enabled = True
        self.course.entrance_exam_minimum_score_pct = 0.50
        self.course.entrance_exam_id = unicode(self.entrance_exam.scope_ids.usage_id)

        self.anonymous_user = AnonymousUserFactory()
        self.request = get_request_for_user(UserFactory())
        modulestore().update_item(self.course, self.request.user.id)  # pylint: disable=no-member

        self.client.login(username=self.request.user.username, password="******")
        CourseEnrollment.enroll(self.request.user, self.course.id)

        self.expected_locked_toc = [
            {
                "active": True,
                "sections": [
                    {
                        "url_name": u"Exam_Sequential_-_Subsection_1",
                        "display_name": u"Exam Sequential - Subsection 1",
                        "graded": True,
                        "format": "",
                        "due": None,
                        "active": True,
                    }
                ],
                "url_name": u"Entrance_Exam_Section_-_Chapter_1",
                "display_name": u"Entrance Exam Section - Chapter 1",
            }
        ]
        self.expected_unlocked_toc = [
            {
                "active": False,
                "sections": [
                    {
                        "url_name": u"Welcome",
                        "display_name": u"Welcome",
                        "graded": False,
                        "format": "",
                        "due": None,
                        "active": False,
                    },
                    {
                        "url_name": u"Lesson_1",
                        "display_name": u"Lesson 1",
                        "graded": False,
                        "format": "",
                        "due": None,
                        "active": False,
                    },
                ],
                "url_name": u"Overview",
                "display_name": u"Overview",
            },
            {"active": False, "sections": [], "url_name": u"Week_1", "display_name": u"Week 1"},
            {"active": False, "sections": [], "url_name": u"Instructor", "display_name": u"Instructor"},
            {
                "active": True,
                "sections": [
                    {
                        "url_name": u"Exam_Sequential_-_Subsection_1",
                        "display_name": u"Exam Sequential - Subsection 1",
                        "graded": True,
                        "format": "",
                        "due": None,
                        "active": True,
                    }
                ],
                "url_name": u"Entrance_Exam_Section_-_Chapter_1",
                "display_name": u"Entrance Exam Section - Chapter 1",
            },
        ]
Example #44
0
 def setUp(self):
     super(TestWeightedProblems, self).setUp()
     self.user = UserFactory()
     self.request = get_request_for_user(self.user)
Example #45
0
 def _pass_entrance_exam(self):
     """ Helper function to pass the entrance exam """
     request = get_request_for_user(self.user)
     answer_entrance_exam_problem(self.course, request, self.problem_1)
Example #46
0
 def test_invalid_course_key(self):
     request = get_request_for_user(UserFactory.create())
     with self.assertRaises(Http404):
         static_tab(request, course_id='edX/toy', tab_slug='new_tab')
Example #47
0
    def setUp(self):
        """
        Test case scaffolding
        """
        super(EntranceExamTestCases, self).setUp()
        self.course = CourseFactory.create(
            metadata={
                'entrance_exam_enabled': True,
            }
        )
        self.chapter = ItemFactory.create(
            parent=self.course,
            display_name='Overview'
        )
        self.welcome = ItemFactory.create(
            parent=self.chapter,
            display_name='Welcome'
        )
        ItemFactory.create(
            parent=self.course,
            category='chapter',
            display_name="Week 1"
        )
        self.chapter_subsection = ItemFactory.create(
            parent=self.chapter,
            category='sequential',
            display_name="Lesson 1"
        )
        chapter_vertical = ItemFactory.create(
            parent=self.chapter_subsection,
            category='vertical',
            display_name='Lesson 1 Vertical - Unit 1'
        )
        ItemFactory.create(
            parent=chapter_vertical,
            category="problem",
            display_name="Problem - Unit 1 Problem 1"
        )
        ItemFactory.create(
            parent=chapter_vertical,
            category="problem",
            display_name="Problem - Unit 1 Problem 2"
        )

        ItemFactory.create(
            category="instructor",
            parent=self.course,
            data="Instructor Tab",
            display_name="Instructor"
        )
        self.entrance_exam = ItemFactory.create(
            parent=self.course,
            category="chapter",
            display_name="Entrance Exam Section - Chapter 1",
            is_entrance_exam=True,
            in_entrance_exam=True
        )
        self.exam_1 = ItemFactory.create(
            parent=self.entrance_exam,
            category='sequential',
            display_name="Exam Sequential - Subsection 1",
            graded=True,
            in_entrance_exam=True
        )
        subsection = ItemFactory.create(
            parent=self.exam_1,
            category='vertical',
            display_name='Exam Vertical - Unit 1'
        )
        problem_xml = MultipleChoiceResponseXMLFactory().build_xml(
            question_text='The correct answer is Choice 3',
            choices=[False, False, True, False],
            choice_names=['choice_0', 'choice_1', 'choice_2', 'choice_3']
        )
        self.problem_1 = ItemFactory.create(
            parent=subsection,
            category="problem",
            display_name="Exam Problem - Problem 1",
            data=problem_xml
        )
        self.problem_2 = ItemFactory.create(
            parent=subsection,
            category="problem",
            display_name="Exam Problem - Problem 2"
        )

        add_entrance_exam_milestone(self.course, self.entrance_exam)

        self.course.entrance_exam_enabled = True
        self.course.entrance_exam_minimum_score_pct = 0.50
        self.course.entrance_exam_id = unicode(self.entrance_exam.scope_ids.usage_id)

        self.anonymous_user = AnonymousUserFactory()
        self.request = get_request_for_user(UserFactory())
        modulestore().update_item(self.course, self.request.user.id)  # pylint: disable=no-member

        self.client.login(username=self.request.user.username, password="******")
        CourseEnrollment.enroll(self.request.user, self.course.id)

        self.expected_locked_toc = (
            [
                {
                    'active': True,
                    'sections': [
                        {
                            'url_name': u'Exam_Sequential_-_Subsection_1',
                            'display_name': u'Exam Sequential - Subsection 1',
                            'graded': True,
                            'format': '',
                            'due': None,
                            'active': True
                        }
                    ],
                    'url_name': u'Entrance_Exam_Section_-_Chapter_1',
                    'display_name': u'Entrance Exam Section - Chapter 1',
                    'display_id': u'entrance-exam-section-chapter-1',
                }
            ]
        )
        self.expected_unlocked_toc = (
            [
                {
                    'active': False,
                    'sections': [
                        {
                            'url_name': u'Welcome',
                            'display_name': u'Welcome',
                            'graded': False,
                            'format': '',
                            'due': None,
                            'active': False
                        },
                        {
                            'url_name': u'Lesson_1',
                            'display_name': u'Lesson 1',
                            'graded': False,
                            'format': '',
                            'due': None,
                            'active': False
                        }
                    ],
                    'url_name': u'Overview',
                    'display_name': u'Overview',
                    'display_id': u'overview'
                },
                {
                    'active': False,
                    'sections': [],
                    'url_name': u'Week_1',
                    'display_name': u'Week 1',
                    'display_id': u'week-1'
                },
                {
                    'active': False,
                    'sections': [],
                    'url_name': u'Instructor',
                    'display_name': u'Instructor',
                    'display_id': u'instructor'
                },
                {
                    'active': True,
                    'sections': [
                        {
                            'url_name': u'Exam_Sequential_-_Subsection_1',
                            'display_name': u'Exam Sequential - Subsection 1',
                            'graded': True,
                            'format': '',
                            'due': None,
                            'active': True
                        }
                    ],
                    'url_name': u'Entrance_Exam_Section_-_Chapter_1',
                    'display_name': u'Entrance Exam Section - Chapter 1',
                    'display_id': u'entrance-exam-section-chapter-1'
                }
            ]
        )
Example #48
0
 def test_invalid_course_key(self):
     self.setup_user()
     request = get_request_for_user(self.user)
     with self.assertRaises(Http404):
         static_tab(request, course_id='edX/toy', tab_slug='new_tab')
 def _pass_entrance_exam(self):
     """ Helper function to pass the entrance exam """
     request = get_request_for_user(self.user)
     answer_entrance_exam_problem(self.course, request, self.problem_1)
Example #50
0
 def setUp(self):
     super(TestWeightedProblems, self).setUp()
     self.user = UserFactory()
     self.request = get_request_for_user(self.user)