def setUpClass(cls):
     super(TestGetProblemGradeDistribution, cls).setUpClass()
     cls.course = CourseFactory.create(
         display_name=u"test course omega \u03a9",
     )
     with cls.store.bulk_operations(cls.course.id, emit_signals=False):
         section = ItemFactory.create(
             parent_location=cls.course.location,
             category="chapter",
             display_name=u"test factory section omega \u03a9",
         )
         cls.sub_section = ItemFactory.create(
             parent_location=section.location,
             category="sequential",
             display_name=u"test subsection omega \u03a9",
         )
         cls.unit = ItemFactory.create(
             parent_location=cls.sub_section.location,
             category="vertical",
             metadata={'graded': True, 'format': 'Homework'},
             display_name=u"test unit omega \u03a9",
         )
         cls.items = []
         for i in xrange(USER_COUNT - 1):
             item = ItemFactory.create(
                 parent_location=cls.unit.location,
                 category="problem",
                 data=StringResponseXMLFactory().build_xml(answer='foo'),
                 metadata={'rerandomize': 'always'},
                 display_name=u"test problem omega \u03a9 " + str(i)
             )
             cls.items.append(item)
             cls.item = item
    def setUpClass(cls):
        # Nose runs setUpClass methods even if a class decorator says to skip
        # the class: https://github.com/nose-devs/nose/issues/946
        # So, skip the test class here if we are not in the LMS.
        if settings.ROOT_URLCONF != 'lms.urls':
            raise unittest.SkipTest('Test only valid in lms')

        super(TestCrowdsourceHinter, cls).setUpClass()
        cls.course = CourseFactory.create(
            display_name='CrowdsourceHinter_Test_Course'
        )
        with cls.store.bulk_operations(cls.course.id, emit_signals=False):
            cls.chapter = ItemFactory.create(
                parent=cls.course, display_name='Overview'
            )
            cls.section = ItemFactory.create(
                parent=cls.chapter, display_name='Welcome'
            )
            cls.unit = ItemFactory.create(
                parent=cls.section, display_name='New Unit'
            )
            cls.xblock = ItemFactory.create(
                parent=cls.unit,
                category='crowdsourcehinter',
                display_name='crowdsourcehinter'
            )

        cls.course_url = reverse(
            'courseware_section',
            kwargs={
                'course_id': cls.course.id.to_deprecated_string(),
                'chapter': 'Overview',
                'section': 'Welcome',
            }
        )
    def set_up_course(self, enable_subsection_grades=True):
        """
        Configures the course for this test.
        """
        # pylint: disable=attribute-defined-outside-init,no-member
        self.course = CourseFactory.create(
            org='edx',
            name='course',
            run='run',
        )
        if not enable_subsection_grades:
            PersistentGradesEnabledFlag.objects.create(enabled=False)

        self.chapter = ItemFactory.create(parent=self.course, category="chapter", display_name="Chapter")
        self.sequential = ItemFactory.create(parent=self.chapter, category='sequential', display_name="Open Sequential")
        self.problem = ItemFactory.create(parent=self.sequential, category='problem', display_name='problem')

        self.score_changed_kwargs = {
            'points_possible': 10,
            'points_earned': 5,
            'user': self.user,
            'course_id': unicode(self.course.id),
            'usage_id': unicode(self.problem.location),
        }

        # this call caches the anonymous id on the user object, saving 4 queries in all happy path tests
        _ = anonymous_id_for_user(self.user, self.course.id)
Beispiel #4
0
    def test_xblock_studio_url(self):

        # Verify course URL
        course_url = u"/course/{}".format(unicode(self.course.id))
        self.assertEqual(xblock_studio_url(self.course), course_url)

        # Verify chapter URL
        chapter = ItemFactory.create(parent_location=self.course.location, category="chapter", display_name="Week 1")
        self.assertEqual(xblock_studio_url(chapter), u"{}?show={}".format(course_url, http.urlquote(chapter.location)))

        # Verify sequential URL
        sequential = ItemFactory.create(
            parent_location=chapter.location, category="sequential", display_name="Lesson 1"
        )
        self.assertEqual(
            xblock_studio_url(sequential), u"{}?show={}".format(course_url, http.urlquote(sequential.location))
        )

        # Verify unit URL
        vertical = ItemFactory.create(parent_location=sequential.location, category="vertical", display_name="Unit")
        self.assertEqual(xblock_studio_url(vertical), u"/container/{}".format(vertical.location))

        # Verify child vertical URL
        child_vertical = ItemFactory.create(
            parent_location=vertical.location, category="vertical", display_name="Child Vertical"
        )
        self.assertEqual(xblock_studio_url(child_vertical), u"/container/{}".format(child_vertical.location))

        # Verify video URL
        video = ItemFactory.create(parent_location=child_vertical.location, category="video", display_name="My Video")
        self.assertIsNone(xblock_studio_url(video))
    def test_repeated_course_module_instantiation(self, loops, default_store, course_depth):

        with modulestore().default_store(default_store):
            course = CourseFactory.create()
            chapter = ItemFactory(parent=course, category='chapter', graded=True)
            section = ItemFactory(parent=chapter, category='sequential')
            __ = ItemFactory(parent=section, category='problem')

        fake_request = self.factory.get(
            reverse('progress', kwargs={'course_id': unicode(course.id)})
        )

        course = modulestore().get_course(course.id, depth=course_depth)

        for _ in xrange(loops):
            field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
                course.id, self.user, course, depth=course_depth
            )
            course_module = get_module_for_descriptor(
                self.user,
                fake_request,
                course,
                field_data_cache,
                course.id,
                course=course
            )
            for chapter in course_module.get_children():
                for section in chapter.get_children():
                    for item in section.get_children():
                        self.assertTrue(item.graded)
 def setUpClass(cls):
     super(GradesEventIntegrationTest, cls).setUpClass()
     cls.store = modulestore()
     with cls.store.default_store(ModuleStoreEnum.Type.split):
         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,
             format="Homework"
         )
         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 2',
             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="p1",
             data=problem_xml,
             metadata={'weight': 2}
         )
    def setUp(self):

        self.course = CourseFactory.create(number='999', display_name='Robot_Super_Course')
        self.overview_chapter = ItemFactory.create(display_name='Overview')
        self.courseware_chapter = ItemFactory.create(display_name='courseware')

        self.test_course = CourseFactory.create(number='666', display_name='Robot_Sub_Course')
        self.other_org_course = CourseFactory.create(org='Other_Org_Course')
        self.sub_courseware_chapter = ItemFactory.create(
            parent_location=self.test_course.location, display_name='courseware'
        )
        self.sub_overview_chapter = ItemFactory.create(
            parent_location=self.sub_courseware_chapter.location,
            display_name='Overview'
        )
        self.welcome_section = ItemFactory.create(
            parent_location=self.overview_chapter.location,
            display_name='Welcome'
        )

        self.global_staff_user = GlobalStaffFactory()
        self.unenrolled_user = UserFactory(last_name="Unenrolled")

        self.enrolled_user = UserFactory(last_name="Enrolled")
        CourseEnrollmentFactory(user=self.enrolled_user, course_id=self.course.id)
        CourseEnrollmentFactory(user=self.enrolled_user, course_id=self.test_course.id)

        self.staff_user = StaffFactory(course=self.course.location)
        self.instructor_user = InstructorFactory(
            course=self.course.location)
        self.org_staff_user = OrgStaffFactory(course=self.course.location)
        self.org_instructor_user = OrgInstructorFactory(
            course=self.course.location)
Beispiel #8
0
    def setUp(self):
        """
        Creates a basic course structure for our course
        """
        super(CourseStatusAPITestCase, self).setUp()

        self.section = ItemFactory.create(
            parent=self.course,
            category='chapter',
        )
        self.sub_section = ItemFactory.create(
            parent=self.section,
            category='sequential',
        )
        self.unit = ItemFactory.create(
            parent=self.sub_section,
            category='vertical',
        )
        self.other_sub_section = ItemFactory.create(
            parent=self.section,
            category='sequential',
        )
        self.other_unit = ItemFactory.create(
            parent=self.other_sub_section,
            category='vertical',
        )
    def setUp(self):
        self.partition = UserPartition(
            0,
            'first_partition',
            'First Partition',
            [
                Group(0, 'alpha'),
                Group(1, 'beta')
            ]
        )

        self.course = CourseFactory.create(
            number=self.COURSE_NUMBER,
            user_partitions=[self.partition]
        )

        self.chapter = ItemFactory.create(
            parent_location=self.course.location,
            category="chapter",
            display_name="test chapter",
        )
        self.sequential = ItemFactory.create(
            parent_location=self.chapter.location,
            category="sequential",
            display_name="Split Test Tests",
        )

        self.student = UserFactory.create()
        CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id)
        self.client.login(username=self.student.username, password='******')
    def setUp(self):
        super(TestTaskExecution, self).setUp()

        self.course = CourseFactory.create(start=datetime(2015, 3, 1))
        self.section = ItemFactory.create(parent=self.course, category='chapter', display_name='Test Section')
        self.subsection = ItemFactory.create(parent=self.section, category='sequential', display_name='Test Subsection')
        self.vertical = ItemFactory.create(parent=self.subsection, category='vertical', display_name='Test Unit')
Beispiel #11
0
    def setup_course(self):
        self.course = CourseFactory.create(data=self.COURSE_DATA)

        # Turn off cache.
        modulestore().request_cache = None
        modulestore().metadata_inheritance_cache_subsystem = None

        chapter = ItemFactory.create(
            parent_location=self.course.location,
            category="sequential",
        )
        self.section = ItemFactory.create(
            parent_location=chapter.location,
            category="sequential"
        )

        # username = robot{0}, password = '******'
        self.users = [
            UserFactory.create()
            for i in range(self.USER_COUNT)
        ]

        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)

        # login all users for acces to Xmodule
        self.clients = {user.username: Client() for user in self.users}
        self.login_statuses = [
            self.clients[user.username].login(
                username=user.username, password='******')
            for user in self.users
        ]

        self.assertTrue(all(self.login_statuses))
    def setUpClass(cls):
        super(TestGradebook, cls).setUpClass()

        # Create a course with the desired grading policy (from our class attribute)
        kwargs = {}
        if cls.grading_policy is not None:
            kwargs['grading_policy'] = cls.grading_policy
        cls.course = CourseFactory.create(**kwargs)

        # Now give it some content
        with cls.store.bulk_operations(cls.course.id, emit_signals=False):
            chapter = ItemFactory.create(
                parent_location=cls.course.location,
                category="sequential",
            )
            section = ItemFactory.create(
                parent_location=chapter.location,
                category="sequential",
                metadata={'graded': True, 'format': 'Homework'}
            )
            cls.items = [
                ItemFactory.create(
                    parent_location=section.location,
                    category="problem",
                    data=StringResponseXMLFactory().build_xml(answer='foo'),
                    metadata={'rerandomize': 'always'}
                )
                for __ in xrange(USER_COUNT - 1)
            ]
    def setUpClass(cls):
        super(SplitTestBase, cls).setUpClass()
        cls.partition = UserPartition(
            0,
            'first_partition',
            'First Partition',
            [
                Group(0, 'alpha'),
                Group(1, 'beta')
            ]
        )

        cls.course = CourseFactory.create(
            number=cls.COURSE_NUMBER,
            user_partitions=[cls.partition]
        )

        cls.chapter = ItemFactory.create(
            parent_location=cls.course.location,
            category="chapter",
            display_name="test chapter",
        )
        cls.sequential = ItemFactory.create(
            parent_location=cls.chapter.location,
            category="sequential",
            display_name="Split Test Tests",
        )
Beispiel #14
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_mock_request(UserFactory())
     cls.user = cls.request.user
     cls.instructor = UserFactory(username='******', is_staff=True)
    def _add_entrance_exam(self):
        """ Sets up entrance exam """
        with self.store.bulk_operations(self.course.id):
            self.course.entrance_exam_enabled = True

            self.entrance_exam = ItemFactory.create(
                parent=self.course,
                category="chapter",
                display_name="Entrance Exam Chapter",
                is_entrance_exam=True,
                in_entrance_exam=True,
            )
            self.subsection_1 = ItemFactory.create(
                parent=self.entrance_exam,
                category='sequential',
                display_name="The Only Exam Sequential",
                graded=True,
                in_entrance_exam=True,
            )
            self.problem_1 = ItemFactory.create(
                parent=self.subsection_1,
                category='problem',
                display_name="The Only Exam Problem",
                graded=True,
                in_entrance_exam=True,
            )

            add_entrance_exam_milestone(self.course, self.entrance_exam)

            self.course.entrance_exam_minimum_score_pct = 0.50
            self.course.entrance_exam_id = unicode(self.entrance_exam.location)
            self.store.update_item(self.course, self.user.id)
Beispiel #16
0
    def setUpClass(cls):
        super(TestCCXGrades, cls).setUpClass()
        cls._course = course = CourseFactory.create(enable_ccx=True)

        # Create a course outline
        cls.mooc_start = start = datetime.datetime(
            2010, 5, 12, 2, 42, tzinfo=pytz.UTC
        )
        chapter = ItemFactory.create(
            start=start, parent=course, category='sequential'
        )
        cls.sections = 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
        cls.problems = [
            [
                ItemFactory.create(
                    parent=section,
                    category="problem",
                    data=StringResponseXMLFactory().build_xml(answer='foo'),
                    metadata={'rerandomize': 'always'}
                ) for _ in xrange(4)
            ] for section in sections
        ]
    def test_resume_course_visibility(self):
        SelfPacedConfiguration(enable_course_home_improvements=True).save()
        chapter = ItemFactory.create(
            category="chapter", parent_location=self.course.location
        )
        section = ItemFactory.create(
            category='section', parent_location=chapter.location
        )
        section_url = reverse(
            'courseware_section',
            kwargs={
                'section': section.url_name,
                'chapter': chapter.url_name,
                'course_id': self.course.id
            }
        )
        self.client.get(section_url)
        info_url = reverse('info', args=(unicode(self.course.id),))

        # Assuring a non-authenticated user cannot see the resume course button.
        resume_course_url = self.get_resume_course_url(info_url)
        self.assertEqual(resume_course_url, None)

        # Assuring an unenrolled user cannot see the resume course button.
        self.setup_user()
        resume_course_url = self.get_resume_course_url(info_url)
        self.assertEqual(resume_course_url, None)

        # Assuring an enrolled user can see the resume course button.
        self.enroll(self.course)
        resume_course_url = self.get_resume_course_url(info_url)
        self.assertEqual(resume_course_url, section_url)
Beispiel #18
0
 def setUpClass(cls):
     super(GradeTestBase, 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
     )
    def setUpClass(cls):
        super(TestSites, cls).setUpClass()
        cls.course = CourseFactory.create(
            display_name='Robot_Super_Course',
            org='TestSiteX',
            emit_signals=True,
        )
        cls.chapter0 = ItemFactory.create(parent_location=cls.course.location, display_name='Overview')
        cls.chapter9 = ItemFactory.create(parent_location=cls.course.location, display_name='factory_chapter')
        cls.section0 = ItemFactory.create(parent_location=cls.chapter0.location, display_name='Welcome')
        cls.section9 = ItemFactory.create(parent_location=cls.chapter9.location, display_name='factory_section')

        cls.course_outside_site = CourseFactory.create(
            display_name='Robot_Course_Outside_Site',
            org='FooX',
            emit_signals=True,
        )

        # have a course which explicitly sets visibility in catalog to False
        cls.course_hidden_visibility = CourseFactory.create(
            display_name='Hidden_course',
            org='TestSiteX',
            catalog_visibility=CATALOG_VISIBILITY_NONE,
            emit_signals=True,
        )

        # have a course which explicitly sets visibility in catalog and about to true
        cls.course_with_visibility = CourseFactory.create(
            display_name='visible_course',
            org='TestSiteX',
            course="foo",
            catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT,
            emit_signals=True,
        )
    def _test_not_indexable(self, store):
        """ test not indexable items """
        # Publish the vertical to start with
        self.publish_item(store, self.vertical.location)
        self.reindex_course(store)
        response = self.search()
        self.assertEqual(response["total"], 4)

        # Add a non-indexable item
        ItemFactory.create(
            parent_location=self.vertical.location,
            category="openassessment",
            display_name="Some other content",
            publish_item=False,
            modulestore=store,
        )
        self.reindex_course(store)
        response = self.search()
        self.assertEqual(response["total"], 4)

        # even after publishing, we should not find the non-indexable item
        self.publish_item(store, self.vertical.location)
        self.reindex_course(store)
        response = self.search()
        self.assertEqual(response["total"], 4)
    def _test_course_location_null(self, store):
        """ Test that course location information is added to index """
        sequential2 = ItemFactory.create(
            parent_location=self.chapter.location,
            category='sequential',
            display_name=None,
            modulestore=store,
            publish_item=True,
            start=datetime(2015, 3, 1, tzinfo=UTC),
        )
        # add a new vertical
        vertical2 = ItemFactory.create(
            parent_location=sequential2.location,
            category='vertical',
            display_name='Subsection 2',
            modulestore=store,
            publish_item=True,
        )
        ItemFactory.create(
            parent_location=vertical2.location,
            category="html",
            display_name="Find Me",
            publish_item=True,
            modulestore=store,
        )
        self.reindex_course(store)
        response = self.search(query_string="Find Me")
        self.assertEqual(response["total"], 1)

        result = response["results"][0]["data"]
        self.assertEqual(result["course_name"], "Search Index Test Course")
        self.assertEqual(result["location"], ["Week 1", CoursewareSearchIndexer.UNNAMED_MODULE_NAME, "Subsection 2"])
    def setUp(self):
        super(TestGetProblemGradeDistribution, self).setUp()

        self.request_factory = RequestFactory()
        self.instructor = AdminFactory.create()
        self.client.login(username=self.instructor.username, password='******')
        self.attempts = 3
        self.course = CourseFactory.create(
            display_name=u"test course omega \u03a9",
        )

        section = ItemFactory.create(
            parent_location=self.course.location,
            category="chapter",
            display_name=u"test factory section omega \u03a9",
        )
        self.sub_section = ItemFactory.create(
            parent_location=section.location,
            category="sequential",
            display_name=u"test subsection omega \u03a9",
        )

        unit = ItemFactory.create(
            parent_location=self.sub_section.location,
            category="vertical",
            metadata={'graded': True, 'format': 'Homework'},
            display_name=u"test unit omega \u03a9",
        )

        self.users = [UserFactory.create(username="******" + str(__)) for __ in xrange(USER_COUNT)]

        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)

        for i in xrange(USER_COUNT - 1):
            category = "problem"
            self.item = ItemFactory.create(
                parent_location=unit.location,
                category=category,
                data=StringResponseXMLFactory().build_xml(answer='foo'),
                metadata={'rerandomize': 'always'},
                display_name=u"test problem omega \u03a9 " + str(i)
            )

            for j, user in enumerate(self.users):
                StudentModuleFactory.create(
                    grade=1 if i < j else 0,
                    max_grade=1 if i < j else 0.5,
                    student=user,
                    course_id=self.course.id,
                    module_state_key=self.item.location,
                    state=json.dumps({'attempts': self.attempts}),
                )

            for j, user in enumerate(self.users):
                StudentModuleFactory.create(
                    course_id=self.course.id,
                    module_type='sequential',
                    module_state_key=self.item.location,
                )
Beispiel #23
0
    def setUp(self):
        """
        Initial data setup
        """
        super(TestHandleItemDeleted, self).setUp()

        self.course = CourseFactory.create()
        self.course.enable_subsection_gating = True
        self.course.save()
        self.chapter = ItemFactory.create(
            parent=self.course,
            category="chapter",
            display_name="Chapter"
        )
        self.open_seq = ItemFactory.create(
            parent=self.chapter,
            category='sequential',
            display_name="Open Sequential"
        )
        self.gated_seq = ItemFactory.create(
            parent=self.chapter,
            category='sequential',
            display_name="Gated Sequential"
        )
        gating_api.add_prerequisite(self.course.id, self.open_seq.location)
        gating_api.set_required_content(self.course.id, self.gated_seq.location, self.open_seq.location, 100)
    def setUp(self):
        """
        Fixtures.
        """
        super(TestSetDueDateExtension, self).setUp()

        self.due = due = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=utc)
        course = CourseFactory.create()
        week1 = ItemFactory.create(due=due, parent=course)
        week2 = ItemFactory.create(due=due, parent=course)
        week3 = ItemFactory.create(parent=course)
        homework = ItemFactory.create(parent=week1)
        assignment = ItemFactory.create(parent=homework, due=due)

        user = UserFactory.create()

        self.course = course
        self.week1 = week1
        self.homework = homework
        self.assignment = assignment
        self.week2 = week2
        self.week3 = week3
        self.user = user

        inject_field_overrides((course, week1, week2, week3, homework, assignment), course, user)
 def setUpClass(cls):
     super(MasqueradeTestCase, cls).setUpClass()
     cls.course = CourseFactory.create(number="masquerade-test", metadata={"start": datetime.now(UTC())})
     cls.info_page = ItemFactory.create(
         category="course_info", parent_location=cls.course.location, data="OOGIE BLOOGIE", display_name="updates"
     )
     cls.chapter = ItemFactory.create(
         parent_location=cls.course.location, category="chapter", display_name="Test Section"
     )
     cls.sequential_display_name = "Test Masquerade Subsection"
     cls.sequential = ItemFactory.create(
         parent_location=cls.chapter.location, category="sequential", display_name=cls.sequential_display_name
     )
     cls.vertical = ItemFactory.create(
         parent_location=cls.sequential.location, category="vertical", display_name="Test Unit"
     )
     problem_xml = OptionResponseXMLFactory().build_xml(
         question_text="The correct answer is Correct",
         num_inputs=2,
         weight=2,
         options=["Correct", "Incorrect"],
         correct_option="Correct",
     )
     cls.problem_display_name = "TestMasqueradeProblem"
     cls.problem = ItemFactory.create(
         parent_location=cls.vertical.location,
         category="problem",
         data=problem_xml,
         display_name=cls.problem_display_name,
     )
Beispiel #26
0
    def setUp(self):
        """
        Fixtures.
        """
        super(TestDataDumps, self).setUp()

        due = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=UTC)
        course = CourseFactory.create()
        week1 = ItemFactory.create(due=due, parent=course)
        week2 = ItemFactory.create(due=due, parent=course)

        homework = ItemFactory.create(
            parent=week1,
            due=due
        )

        user1 = UserFactory.create()
        user2 = UserFactory.create()
        self.course = course
        self.week1 = week1
        self.homework = homework
        self.week2 = week2
        self.user1 = user1
        self.user2 = user2
        signals.extract_dates(None, course.id)
Beispiel #27
0
    def setup_course(self, default_store=None):
        """
        Helper method to create the course.
        """
        if not default_store:
            default_store = self.store.default_modulestore.get_modulestore_type()
        with self.store.default_store(default_store):
            self.course = CourseFactory.create(**self.course_options())
            chapter = ItemFactory.create(parent=self.course, category='chapter')
            self.vertical_block = ItemFactory.create(
                parent_location=chapter.location,
                category='vertical',
                display_name="Vertical"
            )
            self.html_block = ItemFactory.create(
                parent=self.vertical_block,
                category='html',
                data="<p>Test HTML Content<p>"
            )

        # block_name_to_be_tested can be `html_block` or `vertical_block`.
        # These attributes help ensure the positive and negative tests are in sync.
        self.block_to_be_tested = getattr(self, self.block_name_to_be_tested)
        self.block_specific_chrome_html_elements = self.BLOCK_SPECIFIC_CHROME_HTML_ELEMENTS[
            self.block_name_to_be_tested
        ]
 def setUp(self):
     """
     Create a simple course with a video component.
     """
     super(AuthoringMixinTestCase, self).setUp()
     self.course = CourseFactory.create()
     chapter = ItemFactory.create(
         category='chapter',
         parent_location=self.course.location,
         display_name='Test Chapter'
     )
     sequential = ItemFactory.create(
         category='sequential',
         parent_location=chapter.location,
         display_name='Test Sequential'
     )
     vertical = ItemFactory.create(
         category='vertical',
         parent_location=sequential.location,
         display_name='Test Vertical'
     )
     video = ItemFactory.create(
         category='video',
         parent_location=vertical.location,
         display_name='Test Vertical'
     )
     self.vertical_location = vertical.location
     self.video_location = video.location
     self.pet_groups = [Group(1, 'Cat Lovers'), Group(2, 'Dog Lovers')]
 def setUp(self):
     super(GradesServiceTests, self).setUp()
     self.service = GradesService()
     self.course = CourseFactory.create(org='edX', number='DemoX', display_name='Demo_Course', run='Spring2019')
     self.subsection = ItemFactory.create(parent=self.course, category="subsection", display_name="Subsection")
     self.subsection_without_grade = ItemFactory.create(
         parent=self.course,
         category="subsection",
         display_name="Subsection without grade"
     )
     self.user = UserFactory()
     self.grade = PersistentSubsectionGrade.update_or_create_grade(
         user_id=self.user.id,
         course_id=self.course.id,
         usage_key=self.subsection.location,
         first_attempted=None,
         visible_blocks=[],
         earned_all=6.0,
         possible_all=6.0,
         earned_graded=5.0,
         possible_graded=5.0
     )
     self.signal_patcher = patch('lms.djangoapps.grades.signals.signals.SUBSECTION_OVERRIDE_CHANGED.send')
     self.mock_signal = self.signal_patcher.start()
     self.id_patcher = patch('lms.djangoapps.grades.services.create_new_event_transaction_id')
     self.mock_create_id = self.id_patcher.start()
     self.mock_create_id.return_value = 1
     self.type_patcher = patch('lms.djangoapps.grades.services.set_event_transaction_type')
     self.mock_set_type = self.type_patcher.start()
     self.flag_patcher = patch('lms.djangoapps.grades.services.waffle_flags')
     self.mock_waffle_flags = self.flag_patcher.start()
     self.mock_waffle_flags.return_value = {
         REJECTED_EXAM_OVERRIDES_GRADE: MockWaffleFlag(True)
     }
    def _test_not_indexing_unpublished_content(self, store):
        """ add a new one, only appers in index once added """
        # Publish the vertical to start with
        self.publish_item(store, self.vertical.location)
        self.reindex_course(store)
        response = self.search()
        self.assertEqual(response["total"], 4)

        # Now add a new unit to the existing vertical
        ItemFactory.create(
            parent_location=self.vertical.location,
            category="html",
            display_name="Some other content",
            publish_item=False,
            modulestore=store,
        )
        self.reindex_course(store)
        response = self.search()
        self.assertEqual(response["total"], 4)

        # Now publish it and we should find it
        # Publish the vertical as is, and everything should be available
        self.publish_item(store, self.vertical.location)
        self.reindex_course(store)
        response = self.search()
        self.assertEqual(response["total"], 5)
    def test_review_problems(self, num_desired):
        """
        If a user has enough problems to review, they should
        receive a response where there are review problems for them to try.
        """
        self.enroll_student(self.STUDENTS[0]['email'],
                            self.STUDENTS[0]['password'], self.course_actual)
        self.enroll_student(self.STUDENTS[0]['email'],
                            self.STUDENTS[0]['password'], self.course_review)

        # Loading problems so the learner has enough problems in the CSM
        self.client.get(
            reverse('courseware_section',
                    kwargs={
                        'course_id': self.course_actual.id,
                        'chapter': self.chapter_actual.location.name,
                        'section': self.section1_actual.location.name,
                    }))
        self.client.get(
            reverse('courseware_section',
                    kwargs={
                        'course_id': self.course_actual.id,
                        'chapter': self.chapter_actual.location.name,
                        'section': self.section2_actual.location.name,
                    }))
        self.client.get(
            reverse('courseware_section',
                    kwargs={
                        'course_id': self.course_actual.id,
                        'chapter': self.chapter_actual.location.name,
                        'section': self.section3_actual.location.name,
                    }))

        with self.store.bulk_operations(self.course_actual.id,
                                        emit_signals=False):
            review_section_actual = ItemFactory.create(
                parent=self.chapter_actual, display_name='Review Subsection')
            review_unit_actual = ItemFactory.create(
                parent=review_section_actual, display_name='Review Unit')

            review_xblock_actual = ItemFactory.create(  # pylint: disable=unused-variable
                parent=review_unit_actual,
                category='review',
                display_name='Review Tool',
                num_desired=num_desired)

        # Loading the review section
        response = self.client.get(
            reverse('courseware_section',
                    kwargs={
                        'course_id': self.course_actual.id,
                        'chapter': self.chapter_actual.location.name,
                        'section': review_section_actual.location.name,
                    }))

        expected_header_text = 'Review Problems'
        # The problems are defaulted to correct upon load
        # This happens because the problems "raw_possible" field is 0 and the
        # "raw_earned" field is also 0.
        expected_correctness_text = 'correct'
        expected_problems = [
            'Review Problem 1', 'Review Problem 2', 'Review Problem 3',
            'Review Problem 4', 'Review Problem 5', 'Review Problem 6'
        ]

        self.assertIn(expected_header_text, response.content)
        self.assertEqual(response.content.count(expected_correctness_text),
                         num_desired)
        # Since the problems are randomly selected, we have to check
        # the correct number of problems are returned.
        count = 0
        for problem in expected_problems:
            if problem in response.content:
                count += 1
        self.assertEqual(count, num_desired)
        self.assertEqual(response.content.count(self.URL_BEGINNING),
                         num_desired)
    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')
        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")

        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',
            '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'
        }])
Beispiel #33
0
    def setUp(self):
        super(GroupAccessTestCase, self).setUp()

        UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
            [
                Extension("memory", USER_PARTITION_SCHEME_NAMESPACE,
                          MemoryUserPartitionScheme(), None),
                Extension("random", USER_PARTITION_SCHEME_NAMESPACE,
                          MemoryUserPartitionScheme(), None)
            ],
            namespace=USER_PARTITION_SCHEME_NAMESPACE)

        self.cat_group = Group(10, 'cats')
        self.dog_group = Group(20, 'dogs')
        self.worm_group = Group(30, 'worms')
        self.animal_partition = UserPartition(
            0,
            'Pet Partition',
            'which animal are you?',
            [self.cat_group, self.dog_group, self.worm_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.red_group = Group(1000, 'red')
        self.blue_group = Group(2000, 'blue')
        self.gray_group = Group(3000, 'gray')
        self.color_partition = UserPartition(
            100,
            'Color Partition',
            'what color are you?',
            [self.red_group, self.blue_group, self.gray_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.course = CourseFactory.create(
            user_partitions=[self.animal_partition, self.color_partition], )
        with self.store.bulk_operations(self.course.id, emit_signals=False):
            chapter = ItemFactory.create(category='chapter',
                                         parent=self.course)
            section = ItemFactory.create(category='sequential', parent=chapter)
            vertical = ItemFactory.create(category='vertical', parent=section)
            component = ItemFactory.create(category='problem', parent=vertical)

            self.chapter_location = chapter.location
            self.section_location = section.location
            self.vertical_location = vertical.location
            self.component_location = component.location

        self.red_cat = UserFactory()  # student in red and cat groups
        self.set_user_group(self.red_cat, self.animal_partition,
                            self.cat_group)
        self.set_user_group(self.red_cat, self.color_partition, self.red_group)

        self.blue_dog = UserFactory()  # student in blue and dog groups
        self.set_user_group(self.blue_dog, self.animal_partition,
                            self.dog_group)
        self.set_user_group(self.blue_dog, self.color_partition,
                            self.blue_group)

        self.white_mouse = UserFactory()  # student in no group

        self.gray_worm = UserFactory()  # student in deleted group
        self.set_user_group(self.gray_worm, self.animal_partition,
                            self.worm_group)
        self.set_user_group(self.gray_worm, self.color_partition,
                            self.gray_group)
        # delete the gray/worm groups from the partitions now so we can test scenarios
        # for user whose group is missing.
        self.animal_partition.groups.pop()
        self.color_partition.groups.pop()

        # add a staff user, whose access will be unconditional in spite of group access.
        self.staff = StaffFactory.create(course_key=self.course.id)
Beispiel #34
0
    def setUpClass(cls):
        # Nose runs setUpClass methods even if a class decorator says to skip
        # the class: https://github.com/nose-devs/nose/issues/946
        # So, skip the test class here if we are not in the LMS.
        if settings.ROOT_URLCONF != 'lms.urls':
            raise unittest.SkipTest('Test only valid in lms')

        super(TestRecommender, cls).setUpClass()
        cls.course = CourseFactory.create(
            display_name='Recommender_Test_Course')
        with cls.store.bulk_operations(cls.course.id, emit_signals=False):
            cls.chapter = ItemFactory.create(parent=cls.course,
                                             display_name='Overview')
            cls.section = ItemFactory.create(parent=cls.chapter,
                                             display_name='Welcome')
            cls.unit = ItemFactory.create(parent=cls.section,
                                          display_name='New Unit')
            cls.xblock = ItemFactory.create(parent=cls.unit,
                                            category='recommender',
                                            display_name='recommender')
            cls.xblock2 = ItemFactory.create(parent=cls.unit,
                                             category='recommender',
                                             display_name='recommender_second')

        cls.course_url = reverse('courseware_section',
                                 kwargs={
                                     'course_id': text_type(cls.course.id),
                                     'chapter': 'Overview',
                                     'section': 'Welcome',
                                 })

        cls.resource_urls = [
            ("https://courses.edx.org/courses/MITx/3.091X/"
             "2013_Fall/courseware/SP13_Week_4/"
             "SP13_Periodic_Trends_and_Bonding/"),
            ("https://courses.edx.org/courses/MITx/3.091X/"
             "2013_Fall/courseware/SP13_Week_4/SP13_Covalent_Bonding/")
        ]

        cls.test_recommendations = {
            cls.resource_urls[0]: {
                "title":
                "Covalent bonding and periodic trends",
                "url":
                cls.resource_urls[0],
                "description": ("http://people.csail.mit.edu/swli/edx/"
                                "recommendation/img/videopage1.png"),
                "descriptionText": ("short description for Covalent bonding "
                                    "and periodic trends")
            },
            cls.resource_urls[1]: {
                "title":
                "Polar covalent bonds and electronegativity",
                "url":
                cls.resource_urls[1],
                "description": ("http://people.csail.mit.edu/swli/edx/"
                                "recommendation/img/videopage2.png"),
                "descriptionText": ("short description for Polar covalent "
                                    "bonds and electronegativity")
            }
        }
    def test_spoc_gradebook_mongo_calls(self):
        """
        Test that the MongoDB cache is used in API to return grades
        """
        # prepare course structure
        course = ItemFactory.create(
            parent_location=self.course.location,
            category="course",
            display_name="Test course",
        )

        students = []
        for i in xrange(20):
            username = "******" % i
            student = UserFactory.create(username=username)
            CourseEnrollmentFactory.create(user=student,
                                           course_id=self.course.id)
            students.append(student)

        chapter = ItemFactory.create(
            parent=course,
            category='chapter',
            display_name="Chapter",
            publish_item=True,
            start=datetime.datetime(2015, 3, 1, tzinfo=UTC),
        )
        sequential = ItemFactory.create(
            parent=chapter,
            category='sequential',
            display_name="Lesson",
            publish_item=True,
            start=datetime.datetime(2015, 3, 1, tzinfo=UTC),
            metadata={
                'graded': True,
                'format': 'Homework'
            },
        )
        vertical = ItemFactory.create(
            parent=sequential,
            category='vertical',
            display_name='Subsection',
            publish_item=True,
            start=datetime.datetime(2015, 4, 1, tzinfo=UTC),
        )
        for i in xrange(10):
            problem = ItemFactory.create(
                category="problem",
                parent=vertical,
                display_name="A Problem Block %d" % i,
                weight=1,
                publish_item=False,
                metadata={'rerandomize': 'always'},
            )
            for j in students:
                grade = i % 2
                StudentModuleFactory.create(grade=grade,
                                            max_grade=1,
                                            student=j,
                                            course_id=self.course.id,
                                            module_state_key=problem.location)

        # check MongoDB calls count
        url = reverse('spoc_gradebook', kwargs={'course_id': self.course.id})
        with check_mongo_calls(9):
            response = self.client.get(url)
            self.assertEqual(response.status_code, 200)
Beispiel #36
0
    def setUpTestData(cls):
        cls.chapter0 = ItemFactory.create(parent=cls.course,
                                          display_name='Overview')
        cls.chapter9 = ItemFactory.create(parent=cls.course,
                                          display_name='factory_chapter')
        cls.section0 = ItemFactory.create(parent=cls.chapter0,
                                          display_name='Welcome')
        cls.section9 = ItemFactory.create(parent=cls.chapter9,
                                          display_name='factory_section')
        cls.unit0 = ItemFactory.create(parent=cls.section0,
                                       display_name='New Unit 0')

        cls.chapterchrome = ItemFactory.create(parent=cls.course,
                                               display_name='Chrome')
        cls.chromelesssection = ItemFactory.create(parent=cls.chapterchrome,
                                                   display_name='chromeless',
                                                   chrome='none')
        cls.accordionsection = ItemFactory.create(parent=cls.chapterchrome,
                                                  display_name='accordion',
                                                  chrome='accordion')
        cls.tabssection = ItemFactory.create(parent=cls.chapterchrome,
                                             display_name='tabs',
                                             chrome='tabs')
        cls.defaultchromesection = ItemFactory.create(
            parent=cls.chapterchrome,
            display_name='defaultchrome',
        )
        cls.fullchromesection = ItemFactory.create(parent=cls.chapterchrome,
                                                   display_name='fullchrome',
                                                   chrome='accordion,tabs')
        cls.tabtest = ItemFactory.create(parent=cls.chapterchrome,
                                         display_name='progress_tab',
                                         default_tab='progress')

        cls.staff_user = GlobalStaffFactory()
        cls.user = UserFactory()
    def setUpClass(cls):
        # Nose runs setUpClass methods even if a class decorator says to skip
        # the class: https://github.com/nose-devs/nose/issues/946
        # So, skip the test class here if we are not in the LMS.
        if settings.ROOT_URLCONF != 'lms.urls':
            raise unittest.SkipTest('Test only valid in lms')

        super(TestReviewXBlock, cls).setUpClass()

        # Set up for the actual course
        cls.course_actual = CourseFactory.create(
            display_name='Review_Test_Course_ACTUAL',
            org='DillonX',
            number='DAD101x',
            run='3T2017')
        # There are multiple sections so the learner can load different
        # problems, but should only be shown review problems from what they have loaded
        with cls.store.bulk_operations(cls.course_actual.id,
                                       emit_signals=False):
            cls.chapter_actual = ItemFactory.create(parent=cls.course_actual,
                                                    display_name='Overview')
            cls.section1_actual = ItemFactory.create(parent=cls.chapter_actual,
                                                     display_name='Section 1')
            cls.unit1_actual = ItemFactory.create(parent=cls.section1_actual,
                                                  display_name='New Unit 1')
            cls.xblock1_actual = ItemFactory.create(parent=cls.unit1_actual,
                                                    category='problem',
                                                    display_name='Problem 1')
            cls.xblock2_actual = ItemFactory.create(parent=cls.unit1_actual,
                                                    category='problem',
                                                    display_name='Problem 2')
            cls.xblock3_actual = ItemFactory.create(parent=cls.unit1_actual,
                                                    category='problem',
                                                    display_name='Problem 3')
            cls.xblock4_actual = ItemFactory.create(parent=cls.unit1_actual,
                                                    category='problem',
                                                    display_name='Problem 4')
            cls.section2_actual = ItemFactory.create(parent=cls.chapter_actual,
                                                     display_name='Section 2')
            cls.unit2_actual = ItemFactory.create(parent=cls.section2_actual,
                                                  display_name='New Unit 2')
            cls.xblock5_actual = ItemFactory.create(parent=cls.unit2_actual,
                                                    category='problem',
                                                    display_name='Problem 5')
            cls.section3_actual = ItemFactory.create(parent=cls.chapter_actual,
                                                     display_name='Section 3')
            cls.unit3_actual = ItemFactory.create(parent=cls.section3_actual,
                                                  display_name='New Unit 3')
            cls.xblock6_actual = ItemFactory.create(parent=cls.unit3_actual,
                                                    category='problem',
                                                    display_name='Problem 6')

        cls.course_actual_url = reverse('courseware_section',
                                        kwargs={
                                            'course_id':
                                            unicode(cls.course_actual.id),
                                            'chapter':
                                            'Overview',
                                            'section':
                                            'Welcome',
                                        })

        # Set up for the review course where the review problems are hosted
        cls.course_review = CourseFactory.create(
            display_name='Review_Test_Course_REVIEW',
            org='DillonX',
            number='DAD101x_review',
            run='3T2017')
        with cls.store.bulk_operations(cls.course_review.id,
                                       emit_signals=True):
            cls.chapter_review = ItemFactory.create(parent=cls.course_review,
                                                    display_name='Overview')
            cls.section_review = ItemFactory.create(parent=cls.chapter_review,
                                                    display_name='Welcome')
            cls.unit1_review = ItemFactory.create(parent=cls.section_review,
                                                  display_name='New Unit 1')
            cls.xblock1_review = ItemFactory.create(parent=cls.unit1_review,
                                                    category='problem',
                                                    display_name='Problem 1')
            cls.xblock2_review = ItemFactory.create(parent=cls.unit1_review,
                                                    category='problem',
                                                    display_name='Problem 2')
            cls.xblock3_review = ItemFactory.create(parent=cls.unit1_review,
                                                    category='problem',
                                                    display_name='Problem 3')
            cls.xblock4_review = ItemFactory.create(parent=cls.unit1_review,
                                                    category='problem',
                                                    display_name='Problem 4')
            cls.unit2_review = ItemFactory.create(parent=cls.section_review,
                                                  display_name='New Unit 2')
            cls.xblock5_review = ItemFactory.create(parent=cls.unit2_review,
                                                    category='problem',
                                                    display_name='Problem 5')
            cls.unit3_review = ItemFactory.create(parent=cls.section_review,
                                                  display_name='New Unit 3')
            cls.xblock6_review = ItemFactory.create(parent=cls.unit3_review,
                                                    category='problem',
                                                    display_name='Problem 6')

        cls.course_review_url = reverse('courseware_section',
                                        kwargs={
                                            'course_id':
                                            unicode(cls.course_review.id),
                                            'chapter':
                                            'Overview',
                                            'section':
                                            'Welcome',
                                        })
    def test_dashboard_with_resume_buttons_and_view_buttons(self):
        '''
        The Test creates a four-course-card dashboard. The user completes course
        blocks in the even-numbered course cards. The test checks that courses
        with completion data have course cards with "Resume Course" buttons;
        those without have "View Course" buttons.

        '''
        self.override_waffle_switch(True)

        isEven = lambda n: n % 2 == 0

        num_course_cards = 4

        html_for_view_buttons = []
        html_for_resume_buttons = []

        for i in range(num_course_cards):
            course = CourseFactory.create()
            course_enrollment = CourseEnrollmentFactory(
                user=self.user,
                course_id=course.id
            )

            course_key = course_enrollment.course_id
            course_key_string = str(course_key)
            last_completed_block_string = ''
            course_run_string = self._pull_course_run_from_course_key(
                course_key_string)

            # Submit completed course blocks in even-numbered courses.
            if isEven(i):
                block_keys = [
                    ItemFactory.create(
                        category='video',
                        parent_location=course.location,
                        display_name='Video {0}'.format(unicode(number))
                    ).location
                    for number in xrange(5)
                ]
                last_completed_block_string = str(block_keys[-1])

                submit_completions_for_testing(self.user, course_key, block_keys)

            html_for_view_buttons.append(
                self._get_html_for_view_course_button(
                    course_key_string,
                    course_run_string
                )
            )
            html_for_resume_buttons.append(
                self._get_html_for_resume_course_button(
                    course_key_string,
                    last_completed_block_string,
                    course_run_string
                )
            )

        with patch('completion.utilities.visual_progress_enabled', return_value=True):
            response = self.client.get(reverse('dashboard'))

        html_for_view_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_view_buttons
        ]
        html_for_resume_buttons = [
            self._remove_whitespace_from_html_string(button)
            for button in html_for_resume_buttons
        ]
        dashboard_html = self._remove_whitespace_from_html_string(response.content)

        for i in range(num_course_cards):
            expected_button = None
            unexpected_button = None

            if isEven(i):
                expected_button = html_for_resume_buttons[i]
                unexpected_button = html_for_view_buttons[i]
            else:
                expected_button = html_for_view_buttons[i]
                unexpected_button = html_for_resume_buttons[i]

            self.assertIn(
                expected_button,
                dashboard_html
            )
            self.assertNotIn(
                unexpected_button,
                dashboard_html
            )
    def test_library_import(self):
        """
        Try importing a known good library archive, and verify that the
        contents of the library have completely replaced the old contents.
        """
        # Create some blocks to overwrite
        library = LibraryFactory.create(modulestore=self.store)
        lib_key = library.location.library_key
        test_block = ItemFactory.create(
            category="vertical",
            parent_location=library.location,
            user_id=self.user.id,
            publish_item=False,
        )
        test_block2 = ItemFactory.create(
            category="vertical",
            parent_location=library.location,
            user_id=self.user.id,
            publish_item=False
        )
        # Create a library and blocks that should remain unmolested.
        unchanged_lib = LibraryFactory.create()
        unchanged_key = unchanged_lib.location.library_key
        test_block3 = ItemFactory.create(
            category="vertical",
            parent_location=unchanged_lib.location,
            user_id=self.user.id,
            publish_item=False
        )
        test_block4 = ItemFactory.create(
            category="vertical",
            parent_location=unchanged_lib.location,
            user_id=self.user.id,
            publish_item=False
        )
        # Refresh library.
        library = self.store.get_library(lib_key)
        children = [self.store.get_item(child).url_name for child in library.children]
        self.assertEqual(len(children), 2)
        self.assertIn(test_block.url_name, children)
        self.assertIn(test_block2.url_name, children)

        unchanged_lib = self.store.get_library(unchanged_key)
        children = [self.store.get_item(child).url_name for child in unchanged_lib.children]
        self.assertEqual(len(children), 2)
        self.assertIn(test_block3.url_name, children)
        self.assertIn(test_block4.url_name, children)

        extract_dir = path(tempfile.mkdtemp(dir=settings.DATA_DIR))
        # the extract_dir needs to be passed as a relative dir to
        # import_library_from_xml
        extract_dir_relative = path.relpath(extract_dir, settings.DATA_DIR)

        try:
            with tarfile.open(path(TEST_DATA_DIR) / 'imports' / 'library.HhJfPD.tar.gz') as tar:
                safetar_extractall(tar, extract_dir)
            library_items = import_library_from_xml(
                self.store,
                self.user.id,
                settings.GITHUB_REPO_ROOT,
                [extract_dir_relative / 'library'],
                load_error_modules=False,
                static_content_store=contentstore(),
                target_id=lib_key
            )
        finally:
            shutil.rmtree(extract_dir)

        self.assertEqual(lib_key, library_items[0].location.library_key)
        library = self.store.get_library(lib_key)
        children = [self.store.get_item(child).url_name for child in library.children]
        self.assertEqual(len(children), 3)
        self.assertNotIn(test_block.url_name, children)
        self.assertNotIn(test_block2.url_name, children)

        unchanged_lib = self.store.get_library(unchanged_key)
        children = [self.store.get_item(child).url_name for child in unchanged_lib.children]
        self.assertEqual(len(children), 2)
        self.assertIn(test_block3.url_name, children)
        self.assertIn(test_block4.url_name, children)
    def test_too_few_review_problems(self, num_desired):
        """
        If a user does not have enough problems to review, they should
        receive a response to go out and try more problems so they have
        material to review.

        Testing loading 4 problems and asking for 5 and then loading every
        problem and asking for more than that.
        """
        self.enroll_student(self.STUDENTS[0]['email'],
                            self.STUDENTS[0]['password'], self.course_actual)
        self.enroll_student(self.STUDENTS[0]['email'],
                            self.STUDENTS[0]['password'], self.course_review)

        # Want to load fewer problems than num_desired
        self.client.get(
            reverse('courseware_section',
                    kwargs={
                        'course_id': self.course_actual.id,
                        'chapter': self.chapter_actual.location.name,
                        'section': self.section1_actual.location.name,
                    }))
        if num_desired > 6:
            self.client.get(
                reverse('courseware_section',
                        kwargs={
                            'course_id': self.course_actual.id,
                            'chapter': self.chapter_actual.location.name,
                            'section': self.section2_actual.location.name,
                        }))
            self.client.get(
                reverse('courseware_section',
                        kwargs={
                            'course_id': self.course_actual.id,
                            'chapter': self.chapter_actual.location.name,
                            'section': self.section3_actual.location.name,
                        }))

        with self.store.bulk_operations(self.course_actual.id,
                                        emit_signals=False):
            review_section_actual = ItemFactory.create(
                parent=self.chapter_actual, display_name='Review Subsection')
            review_unit_actual = ItemFactory.create(
                parent=review_section_actual, display_name='Review Unit')

            review_xblock_actual = ItemFactory.create(  # pylint: disable=unused-variable
                parent=review_unit_actual,
                category='review',
                display_name='Review Tool',
                num_desired=num_desired)

        # Loading the review section
        response = self.client.get(
            reverse('courseware_section',
                    kwargs={
                        'course_id': self.course_actual.id,
                        'chapter': self.chapter_actual.location.name,
                        'section': review_section_actual.location.name,
                    }))

        expected_h2 = 'Nothing to review'

        self.assertIn(expected_h2, response.content)
 def setUp(self):
     super(TestRebindModule, self).setUp()
     self.homework = self.add_graded_section_to_course('homework')
     self.lti = ItemFactory.create(category='lti', parent=self.homework)
     self.user = UserFactory.create()
     self.anon_user = AnonymousUser()
Beispiel #42
0
 def _add_simple_content_block(self):
     """ Adds simple HTML block to library """
     return ItemFactory.create(
         category="html", parent_location=self.library.location,
         user_id=self.user.id, publish_item=False
     )
Beispiel #43
0
    def setup_data(self, store_type=ModuleStoreEnum.Type.mongo):
        """ Create courses and add some test blocks. """

        with self.store.default_store(store_type):

            self.course = CourseFactory.create(
                display_name='An Introduction to API Testing')
            self.course_id = text_type(self.course.id)

            with self.store.bulk_operations(self.course.id):

                self.chapter_1 = ItemFactory.create(
                    parent_location=self.course.location,
                    category='chapter',
                    display_name='Week 1')
                self.chapter_2 = ItemFactory.create(
                    parent_location=self.course.location,
                    category='chapter',
                    display_name='Week 2')

                self.sequential_1 = ItemFactory.create(
                    parent_location=self.chapter_1.location,
                    category='sequential',
                    display_name='Lesson 1')
                self.sequential_2 = ItemFactory.create(
                    parent_location=self.chapter_1.location,
                    category='sequential',
                    display_name='Lesson 2')

                self.vertical_1 = ItemFactory.create(
                    parent_location=self.sequential_1.location,
                    category='vertical',
                    display_name='Subsection 1')
                self.vertical_2 = ItemFactory.create(
                    parent_location=self.sequential_2.location,
                    category='vertical',
                    display_name='Subsection 2')
                self.vertical_3 = ItemFactory.create(
                    parent_location=self.sequential_2.location,
                    category='vertical',
                    display_name='Subsection 3')

                self.html_1 = ItemFactory.create(
                    parent_location=self.vertical_2.location,
                    category='html',
                    display_name='Details 1')

        self.path = [
            PathItem(self.chapter_1.location, self.chapter_1.display_name),
            PathItem(self.sequential_2.location,
                     self.sequential_2.display_name),
        ]

        self.bookmark_1 = BookmarkFactory.create(
            user=self.user,
            course_key=self.course_id,
            usage_key=self.sequential_1.location,
            xblock_cache=XBlockCache.create({
                'display_name':
                self.sequential_1.display_name,
                'usage_key':
                self.sequential_1.location,
            }),
        )
        self.bookmark_2 = BookmarkFactory.create(
            user=self.user,
            course_key=self.course_id,
            usage_key=self.sequential_2.location,
            xblock_cache=XBlockCache.create({
                'display_name':
                self.sequential_2.display_name,
                'usage_key':
                self.sequential_2.location,
            }),
        )
        self.bookmark_3 = BookmarkFactory.create(
            user=self.user,
            course_key=self.course_id,
            usage_key=self.vertical_3.location,
            xblock_cache=XBlockCache.create({
                'display_name':
                self.vertical_3.display_name,
                'usage_key':
                self.vertical_3.location,
            }),
        )
        self.bookmark_4 = BookmarkFactory.create(
            user=self.user,
            course_key=self.course_id,
            usage_key=self.chapter_2.location,
            xblock_cache=XBlockCache.create({
                'display_name':
                self.chapter_2.display_name,
                'usage_key':
                self.chapter_2.location,
            }),
        )

        self.other_course = CourseFactory.create(
            display_name='An Introduction to API Testing 2')

        with self.store.bulk_operations(self.other_course.id):

            self.other_chapter_1 = ItemFactory.create(
                parent_location=self.other_course.location,
                category='chapter',
                display_name='Other Week 1')
            self.other_sequential_1 = ItemFactory.create(
                parent_location=self.other_chapter_1.location,
                category='sequential',
                display_name='Other Lesson 1')
            self.other_sequential_2 = ItemFactory.create(
                parent_location=self.other_chapter_1.location,
                category='sequential',
                display_name='Other Lesson 2')
            self.other_vertical_1 = ItemFactory.create(
                parent_location=self.other_sequential_1.location,
                category='vertical',
                display_name='Other Subsection 1')
            self.other_vertical_2 = ItemFactory.create(
                parent_location=self.other_sequential_1.location,
                category='vertical',
                display_name='Other Subsection 2')

            # self.other_vertical_1 has two parents
            self.other_sequential_2.children.append(
                self.other_vertical_1.location)
            modulestore().update_item(self.other_sequential_2, self.admin.id)

        self.other_bookmark_1 = BookmarkFactory.create(
            user=self.user,
            course_key=text_type(self.other_course.id),
            usage_key=self.other_vertical_1.location,
            xblock_cache=XBlockCache.create({
                'display_name':
                self.other_vertical_1.display_name,
                'usage_key':
                self.other_vertical_1.location,
            }),
        )
    def setUpClass(cls):
        """
        Set up an array of various courses to be tested.
        """
        # setUpClassAndTestData() already calls setUpClass on SharedModuleStoreTestCase
        # pylint: disable=super-method-not-called
        with super(TestCourseOutlinePage, cls).setUpClassAndTestData():
            cls.courses = []
            course = CourseFactory.create()
            with cls.store.bulk_operations(course.id):
                chapter = ItemFactory.create(category='chapter', parent_location=course.location)
                sequential = ItemFactory.create(category='sequential', parent_location=chapter.location)
                vertical = ItemFactory.create(category='vertical', parent_location=sequential.location)
            course.children = [chapter]
            chapter.children = [sequential]
            sequential.children = [vertical]
            cls.courses.append(course)

            course = CourseFactory.create()
            with cls.store.bulk_operations(course.id):
                chapter = ItemFactory.create(category='chapter', parent_location=course.location)
                sequential = ItemFactory.create(category='sequential', parent_location=chapter.location)
                sequential2 = ItemFactory.create(category='sequential', parent_location=chapter.location)
                vertical = ItemFactory.create(
                    category='vertical',
                    parent_location=sequential.location,
                    display_name="Vertical 1"
                )
                vertical2 = ItemFactory.create(
                    category='vertical',
                    parent_location=sequential2.location,
                    display_name="Vertical 2"
                )
            course.children = [chapter]
            chapter.children = [sequential, sequential2]
            sequential.children = [vertical]
            sequential2.children = [vertical2]
            cls.courses.append(course)

            course = CourseFactory.create()
            with cls.store.bulk_operations(course.id):
                chapter = ItemFactory.create(category='chapter', parent_location=course.location)
                sequential = ItemFactory.create(
                    category='sequential',
                    parent_location=chapter.location,
                    due=datetime.datetime.now(),
                    graded=True,
                    format='Homework',
                )
                vertical = ItemFactory.create(category='vertical', parent_location=sequential.location)
            course.children = [chapter]
            chapter.children = [sequential]
            sequential.children = [vertical]
            cls.courses.append(course)
Beispiel #45
0
 def test_item_factory(self):
     """Test that the item factory works correctly."""
     course = CourseFactory.create()
     item = ItemFactory.create(parent_location=course.location)
     self.assertIsInstance(item, SequenceDescriptor)
    def test_has_access_in_preview_mode_with_group(self):
        """
        Test that a user masquerading as a member of a group sees appropriate content in preview mode.
        """
        # Note about UserPartition and UserPartition Group IDs: these must not conflict with IDs used
        # by dynamic user partitions.
        partition_id = MINIMUM_STATIC_PARTITION_ID
        group_0_id = MINIMUM_STATIC_PARTITION_ID + 1
        group_1_id = MINIMUM_STATIC_PARTITION_ID + 2
        user_partition = UserPartition(
            partition_id,
            'Test User Partition',
            '', [Group(group_0_id, 'Group 1'),
                 Group(group_1_id, 'Group 2')],
            scheme_id='cohort')
        self.course.user_partitions.append(user_partition)
        self.course.cohort_config = {'cohorted': True}

        chapter = ItemFactory.create(category="chapter",
                                     parent_location=self.course.location)
        chapter.group_access = {partition_id: [group_0_id]}

        modulestore().update_item(self.course, ModuleStoreEnum.UserID.test)

        # User should not be able to preview when masquerading as student (and not in the group above).
        with patch('courseware.access.get_user_role') as mock_user_role:
            mock_user_role.return_value = 'student'
            self.assertFalse(
                bool(
                    access.has_access(self.global_staff,
                                      'load',
                                      chapter,
                                      course_key=self.course.id)))

        # Should be able to preview when in staff or instructor role.
        for mocked_role in ['staff', 'instructor']:
            with patch('courseware.access.get_user_role') as mock_user_role:
                mock_user_role.return_value = mocked_role
                self.assertTrue(
                    bool(
                        access.has_access(self.global_staff,
                                          'load',
                                          chapter,
                                          course_key=self.course.id)))

        # Now install masquerade group and set staff as a member of that.
        self.assertEqual(
            200,
            masquerade_as_group_member(self.global_staff, self.course,
                                       partition_id, group_0_id))
        # Can load the chapter since user is in the group.
        self.assertTrue(
            bool(
                access.has_access(self.global_staff,
                                  'load',
                                  chapter,
                                  course_key=self.course.id)))

        # Move the user to be a part of the second group.
        self.assertEqual(
            200,
            masquerade_as_group_member(self.global_staff, self.course,
                                       partition_id, group_1_id))
        # Cannot load the chapter since user is in a different group.
        self.assertFalse(
            bool(
                access.has_access(self.global_staff,
                                  'load',
                                  chapter,
                                  course_key=self.course.id)))
Beispiel #47
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_mock_request(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)
Beispiel #48
0
 def setUp(self):
     super().setUp()
     self.course = CourseFactory.create()
     for i in range(4):
         ItemFactory(parent=self.course, category="sequential", display_name="Section {}".format(i))
Beispiel #49
0
    def test_studio_user_permissions(self):
        """
        Test that user could attach to the problem only libraries that he has access (or which were created by him).
        This test was created on the basis of bug described in the pull requests on github:
        https://github.com/edx/edx-platform/pull/11331
        https://github.com/edx/edx-platform/pull/11611
        """
        self._create_library(org='admin_org_1',
                             library='lib_adm_1',
                             display_name='admin_lib_1')
        self._create_library(org='admin_org_2',
                             library='lib_adm_2',
                             display_name='admin_lib_2')

        self._login_as_non_staff_user()

        self._create_library(org='staff_org_1',
                             library='lib_staff_1',
                             display_name='staff_lib_1')
        self._create_library(org='staff_org_2',
                             library='lib_staff_2',
                             display_name='staff_lib_2')

        with modulestore().default_store(ModuleStoreEnum.Type.split):
            course = CourseFactory.create()

        instructor_role = CourseInstructorRole(course.id)
        auth.add_users(self.user, instructor_role, self.non_staff_user)

        lib_block = ItemFactory.create(category='library_content',
                                       parent_location=course.location,
                                       user_id=self.non_staff_user.id,
                                       publish_item=False)

        def _get_settings_html():
            """
            Helper function to get block settings HTML
            Used to check the available libraries.
            """
            edit_view_url = reverse_usage_url("xblock_view_handler",
                                              lib_block.location,
                                              {"view_name": STUDIO_VIEW})

            resp = self.client.get_json(edit_view_url)
            self.assertEquals(resp.status_code, 200)

            return parse_json(resp)['html']

        self._login_as_staff_user()
        staff_settings_html = _get_settings_html()
        self.assertIn('staff_lib_1', staff_settings_html)
        self.assertIn('staff_lib_2', staff_settings_html)
        self.assertIn('admin_lib_1', staff_settings_html)
        self.assertIn('admin_lib_2', staff_settings_html)

        self._login_as_non_staff_user()
        response = self.client.get_json(LIBRARY_REST_URL)
        staff_libs = parse_json(response)
        self.assertEquals(2, len(staff_libs))

        non_staff_settings_html = _get_settings_html()
        self.assertIn('staff_lib_1', non_staff_settings_html)
        self.assertIn('staff_lib_2', non_staff_settings_html)
        self.assertNotIn('admin_lib_1', non_staff_settings_html)
        self.assertNotIn('admin_lib_2', non_staff_settings_html)
Beispiel #50
0
    def setUpClass(cls):
        super(TestGetModuleScore, cls).setUpClass()
        cls.course = CourseFactory.create()
        cls.chapter = ItemFactory.create(parent=cls.course,
                                         category="chapter",
                                         display_name="Test Chapter")
        cls.seq1 = ItemFactory.create(parent=cls.chapter,
                                      category='sequential',
                                      display_name="Test Sequential 1",
                                      graded=True)
        cls.seq2 = ItemFactory.create(parent=cls.chapter,
                                      category='sequential',
                                      display_name="Test Sequential 2",
                                      graded=True)
        cls.seq3 = ItemFactory.create(parent=cls.chapter,
                                      category='sequential',
                                      display_name="Test Sequential 3",
                                      graded=True)
        cls.vert1 = ItemFactory.create(parent=cls.seq1,
                                       category='vertical',
                                       display_name='Test Vertical 1')
        cls.vert2 = ItemFactory.create(parent=cls.seq2,
                                       category='vertical',
                                       display_name='Test Vertical 2')
        cls.vert3 = ItemFactory.create(parent=cls.seq3,
                                       category='vertical',
                                       display_name='Test Vertical 3')
        cls.randomize = ItemFactory.create(parent=cls.vert2,
                                           category='randomize',
                                           display_name='Test Randomize')
        cls.library_content = ItemFactory.create(
            parent=cls.vert3,
            category='library_content',
            display_name='Test Library Content')
        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.problem1 = ItemFactory.create(parent=cls.vert1,
                                          category="problem",
                                          display_name="Test Problem 1",
                                          data=problem_xml)
        cls.problem2 = ItemFactory.create(parent=cls.vert1,
                                          category="problem",
                                          display_name="Test Problem 2",
                                          data=problem_xml)
        cls.problem3 = ItemFactory.create(parent=cls.randomize,
                                          category="problem",
                                          display_name="Test Problem 3",
                                          data=problem_xml)
        cls.problem4 = ItemFactory.create(parent=cls.randomize,
                                          category="problem",
                                          display_name="Test Problem 4",
                                          data=problem_xml)

        cls.problem5 = ItemFactory.create(parent=cls.library_content,
                                          category="problem",
                                          display_name="Test Problem 5",
                                          data=problem_xml)
        cls.problem6 = ItemFactory.create(parent=cls.library_content,
                                          category="problem",
                                          display_name="Test Problem 6",
                                          data=problem_xml)
 def setUp(self):
     super(TestCourseUpdateResolver, self).setUp()
     self.course = CourseFactory(highlights_enabled_for_messaging=True, self_paced=True)
     with self.store.bulk_operations(self.course.id):
         ItemFactory.create(parent=self.course, category='chapter', highlights=[u'good stuff'])
Beispiel #52
0
 def setUpClass(cls):
     super(TestFindUnit, cls).setUpClass()
     cls.course = CourseFactory.create()
     with cls.store.bulk_operations(cls.course.id, emit_signals=False):
         week1 = ItemFactory.create(parent=cls.course)
         cls.homework = ItemFactory.create(parent=week1)
Beispiel #53
0
    def set_up_course(self,
                      enable_persistent_grades=True,
                      create_multiple_subsections=False,
                      course_end=None):
        """
        Configures the course for this test.
        """
        self.course = CourseFactory.create(org='edx',
                                           name='course',
                                           run='run',
                                           end=course_end)
        if not enable_persistent_grades:
            PersistentGradesEnabledFlag.objects.create(enabled=False)

        self.chapter = ItemFactory.create(parent=self.course,
                                          category="chapter",
                                          display_name="Chapter")
        self.sequential = ItemFactory.create(parent=self.chapter,
                                             category='sequential',
                                             display_name="Sequential1")
        self.problem = ItemFactory.create(parent=self.sequential,
                                          category='problem',
                                          display_name='Problem')

        if create_multiple_subsections:
            seq2 = ItemFactory.create(parent=self.chapter,
                                      category='sequential')
            ItemFactory.create(parent=seq2, category='problem')

        self.frozen_now_datetime = datetime.now().replace(tzinfo=pytz.UTC)
        self.frozen_now_timestamp = to_timestamp(self.frozen_now_datetime)

        self.problem_weighted_score_changed_kwargs = OrderedDict([
            ('weighted_earned', 1.0),
            ('weighted_possible', 2.0),
            ('user_id', self.user.id),
            ('anonymous_user_id', 5),
            ('course_id', unicode(self.course.id)),
            ('usage_id', unicode(self.problem.location)),
            ('only_if_higher', None),
            ('modified', self.frozen_now_datetime),
            ('score_db_table',
             ScoreDatabaseTableEnum.courseware_student_module),
        ])

        create_new_event_transaction_id()

        self.recalculate_subsection_grade_kwargs = OrderedDict([
            ('user_id', self.user.id),
            ('course_id', unicode(self.course.id)),
            ('usage_id', unicode(self.problem.location)),
            ('anonymous_user_id', 5),
            ('only_if_higher', None),
            ('expected_modified_time', self.frozen_now_timestamp),
            ('score_deleted', False),
            ('event_transaction_id', unicode(get_event_transaction_id())),
            ('event_transaction_type', u'edx.grades.problem.submitted'),
            ('score_db_table',
             ScoreDatabaseTableEnum.courseware_student_module),
        ])

        # this call caches the anonymous id on the user object, saving 4 queries in all happy path tests
        _ = anonymous_id_for_user(self.user, self.course.id)
Beispiel #54
0
    def initialize_course(cls, course):
        """
        Sets up the structure of the test course.
        """
        course.self_paced = True
        cls.store.update_item(course, cls.staff.id)

        cls.section = ItemFactory.create(
            parent_location=course.location,
            category="chapter",
        )
        cls.subsection1 = ItemFactory.create(
            parent_location=cls.section.location,
            category="sequential",
        )
        unit1 = ItemFactory.create(
            parent_location=cls.subsection1.location,
            category="vertical",
        )
        ItemFactory.create(
            parent_location=unit1.location,
            category="video",
        )
        ItemFactory.create(
            parent_location=unit1.location,
            category="problem",
        )

        cls.subsection2 = ItemFactory.create(
            parent_location=cls.section.location,
            category="sequential",
        )
        unit2 = ItemFactory.create(
            parent_location=cls.subsection2.location,
            category="vertical",
        )
        unit3 = ItemFactory.create(
            parent_location=cls.subsection2.location,
            category="vertical",
        )
        ItemFactory.create(
            parent_location=unit3.location,
            category="video",
        )
        ItemFactory.create(
            parent_location=unit3.location,
            category="video",
        )
Beispiel #55
0
    def setup_course_with_grading(self, start=None, end=None):
        grading_course = CourseFactory.create(
            start=start,
            end=end,
            org='gradeX',
            run='GRAD1',
            display_name="Test Grading Course",
            grading_policy={
                "GRADER": [
                    {
                        "type": "Homework",
                        "min_count": 1,
                        "drop_count": 0,
                        "short_label": "HW",
                        "weight": 0.5
                    },
                    {
                        "type": "Midterm Exam",
                        "min_count": 1,
                        "drop_count": 0,
                        "short_label": "ME",
                        "weight": 0.5
                    },
                ],
                "GRADE_CUTOFFS": {
                    'A': .9,
                    'B': .33
                }
            },
        )

        test_data = '<html>{}</html>'.format(str(uuid.uuid4()))
        chapter1 = ItemFactory.create(
            category="chapter",
            parent_location=grading_course.location,
            display_name="Chapter 1",
        )
        chapter2 = ItemFactory.create(
            category="chapter",
            parent_location=grading_course.location,
            display_name="Chapter 2",
        )
        ItemFactory.create(
            category="sequential",
            parent_location=chapter1.location,
            display_name="Sequence 1",
        )
        sequential2 = ItemFactory.create(
            category="sequential",
            parent_location=chapter2.location,
            display_name="Sequence 2",
            graded=True,
            metadata={
                'rerandomize': 'always',
                'graded': True,
                'format': "Homework"
            },
        )
        vertical1 = ItemFactory.create(
            category="vertical",
            parent_location=sequential2.location,
            display_name="Vertical 1",
        )
        sequential3 = ItemFactory.create(
            category="sequential",
            parent_location=chapter2.location,
            display_name="Sequence 3",
            graded=True,
            metadata={
                'rerandomize': 'always',
                'graded': True,
                'format': "Midterm Exam"
            },
        )
        vertical2 = ItemFactory.create(
            category="vertical",
            parent_location=sequential3.location,
            display_name="Vertical 2",
        )
        item = ItemFactory.create(
            parent_location=vertical1.location,
            category='mentoring',
            display_name=u"test mentoring homework",
        )
        item2 = ItemFactory.create(
            parent_location=vertical2.location,
            category='mentoring',
            display_name=u"test mentoring midterm",
        )

        grading_course = self.store.get_course(grading_course.id)
        setattr(grading_course, 'homework_assignment', item)
        setattr(grading_course, 'midterm_assignment', item2)
        return grading_course
Beispiel #56
0
    def setUp(self):
        """
        Preparation for the test execution
        """
        super(StructuredTagsAsideTestCase, self).setUp()
        self.aside_name = 'tagging_aside'
        self.aside_tag_dif = 'difficulty'
        self.aside_tag_dif_value = 'Hard'
        self.aside_tag_dif_value2 = 'Easy'
        self.aside_tag_lo = 'learning_outcome'

        course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
        self.course = ItemFactory.create(
            parent_location=course.location,
            category="course",
            display_name="Test course",
        )
        self.chapter = ItemFactory.create(
            parent_location=self.course.location,
            category='chapter',
            display_name="Week 1",
            publish_item=True,
            start=datetime(2015, 3, 1, tzinfo=UTC),
        )
        self.sequential = ItemFactory.create(
            parent_location=self.chapter.location,
            category='sequential',
            display_name="Lesson 1",
            publish_item=True,
            start=datetime(2015, 3, 1, tzinfo=UTC),
        )
        self.vertical = ItemFactory.create(
            parent_location=self.sequential.location,
            category='vertical',
            display_name='Subsection 1',
            publish_item=True,
            start=datetime(2015, 4, 1, tzinfo=UTC),
        )
        self.problem = ItemFactory.create(
            category="problem",
            parent_location=self.vertical.location,
            display_name="A Problem Block",
            weight=1,
            user_id=self.user.id,
            publish_item=False,
        )
        self.video = ItemFactory.create(parent_location=self.vertical.location,
                                        category='video',
                                        display_name='My Video',
                                        user_id=self.user.id)

        _init_data = [{
            'name': 'difficulty',
            'title': 'Difficulty',
            'values': ['Easy', 'Medium', 'Hard'],
        }, {
            'name':
            'learning_outcome',
            'title':
            'Learning outcome',
            'values':
            ['Learned nothing', 'Learned a few things', 'Learned everything']
        }]

        for tag in _init_data:
            category = TagCategories.objects.create(name=tag['name'],
                                                    title=tag['title'])
            for val in tag['values']:
                TagAvailableValues.objects.create(category=category, value=val)

        config = StudioConfig.current()
        config.enabled = True
        config.save()
Beispiel #57
0
    def set_up_course(cls):
        """
        Set up a course for testing gated content.
        """
        cls.course = CourseFactory.create(org='edX',
                                          number='EDX101',
                                          run='EDX101_RUN1',
                                          display_name='edX 101')
        with modulestore().bulk_operations(cls.course.id):
            cls.course.enable_subsection_gating = True
            grading_policy = {
                "GRADER": [{
                    "type": "Homework",
                    "min_count": 3,
                    "drop_count": 0,
                    "short_label": "HW",
                    "weight": 1.0
                }]
            }
            cls.course.grading_policy = grading_policy
            cls.course.save()
            cls.store.update_item(cls.course, 0)

            # create chapter
            cls.chapter1 = ItemFactory.create(
                parent_location=cls.course.location,
                category='chapter',
                display_name='chapter 1')

            # create sequentials
            cls.seq1 = ItemFactory.create(
                parent_location=cls.chapter1.location,
                category='sequential',
                display_name='gating sequential 1',
                graded=True,
                format='Homework',
            )
            cls.seq2 = ItemFactory.create(
                parent_location=cls.chapter1.location,
                category='sequential',
                display_name='gated sequential 2',
                graded=True,
                format='Homework',
            )
            cls.seq3 = ItemFactory.create(
                parent_location=cls.chapter1.location,
                category='sequential',
                display_name='sequential 3',
                graded=True,
                format='Homework',
            )

            # create problem
            cls.gating_prob1 = ItemFactory.create(
                parent_location=cls.seq1.location,
                category='problem',
                display_name='gating problem 1',
            )
            cls.gated_prob2 = ItemFactory.create(
                parent_location=cls.seq2.location,
                category='problem',
                display_name='gated problem 2',
            )
            cls.prob3 = ItemFactory.create(
                parent_location=cls.seq3.location,
                category='problem',
                display_name='problem 3',
            )
    def setUp(self):
        super(TestRecommender, self).setUp()

        self.course = CourseFactory.create(
            display_name='Recommender_Test_Course')
        self.chapter = ItemFactory.create(parent=self.course,
                                          display_name='Overview')
        self.section = ItemFactory.create(parent=self.chapter,
                                          display_name='Welcome')
        self.unit = ItemFactory.create(parent=self.section,
                                       display_name='New Unit')
        self.xblock = ItemFactory.create(parent=self.unit,
                                         category='recommender',
                                         display_name='recommender')
        self.xblock2 = ItemFactory.create(parent=self.unit,
                                          category='recommender',
                                          display_name='recommender_second')

        self.course_url = reverse('courseware_section',
                                  kwargs={
                                      'course_id':
                                      self.course.id.to_deprecated_string(),
                                      'chapter':
                                      'Overview',
                                      'section':
                                      'Welcome',
                                  })

        self.resource_urls = [
            ("https://courses.edx.org/courses/MITx/3.091X/"
             "2013_Fall/courseware/SP13_Week_4/"
             "SP13_Periodic_Trends_and_Bonding/"),
            ("https://courses.edx.org/courses/MITx/3.091X/"
             "2013_Fall/courseware/SP13_Week_4/SP13_Covalent_Bonding/")
        ]

        self.test_recommendations = {
            self.resource_urls[0]: {
                "title":
                "Covalent bonding and periodic trends",
                "url":
                self.resource_urls[0],
                "description": ("http://people.csail.mit.edu/swli/edx/"
                                "recommendation/img/videopage1.png"),
                "descriptionText": ("short description for Covalent bonding "
                                    "and periodic trends")
            },
            self.resource_urls[1]: {
                "title":
                "Polar covalent bonds and electronegativity",
                "url":
                self.resource_urls[1],
                "description": ("http://people.csail.mit.edu/swli/edx/"
                                "recommendation/img/videopage2.png"),
                "descriptionText": ("short description for Polar covalent "
                                    "bonds and electronegativity")
            }
        }

        for idx, student in enumerate(self.STUDENTS):
            username = "******".format(idx)
            self.create_account(username, student['email'],
                                student['password'])
            self.activate_user(student['email'])

        self.staff_user = GlobalStaffFactory()
Beispiel #59
0
    def setUp(self):
        super(TestNavigation, self).setUp()
        self.test_course = CourseFactory.create()
        self.course = CourseFactory.create()
        self.chapter0 = ItemFactory.create(parent=self.course,
                                           display_name='Overview')
        self.chapter9 = ItemFactory.create(parent=self.course,
                                           display_name='factory_chapter')
        self.section0 = ItemFactory.create(parent=self.chapter0,
                                           display_name='Welcome')
        self.section9 = ItemFactory.create(parent=self.chapter9,
                                           display_name='factory_section')
        self.unit0 = ItemFactory.create(parent=self.section0,
                                        display_name='New Unit')

        self.chapterchrome = ItemFactory.create(parent=self.course,
                                                display_name='Chrome')
        self.chromelesssection = ItemFactory.create(parent=self.chapterchrome,
                                                    display_name='chromeless',
                                                    chrome='none')
        self.accordionsection = ItemFactory.create(parent=self.chapterchrome,
                                                   display_name='accordion',
                                                   chrome='accordion')
        self.tabssection = ItemFactory.create(parent=self.chapterchrome,
                                              display_name='tabs',
                                              chrome='tabs')
        self.defaultchromesection = ItemFactory.create(
            parent=self.chapterchrome,
            display_name='defaultchrome',
        )
        self.fullchromesection = ItemFactory.create(parent=self.chapterchrome,
                                                    display_name='fullchrome',
                                                    chrome='accordion,tabs')
        self.tabtest = ItemFactory.create(parent=self.chapterchrome,
                                          display_name='progress_tab',
                                          default_tab='progress')

        # Create student accounts and activate them.
        for i in range(len(self.STUDENT_INFO)):
            email, password = self.STUDENT_INFO[i]
            username = '******'.format(i)
            self.create_account(username, email, password)
            self.activate_user(email)

        self.staff_user = GlobalStaffFactory()
Beispiel #60
0
    def test_unit_in_section(self):
        """
        Test when the structure is Course -> Section -> Unit.

        Studio disallows this, but it's possible to craft in OLX. This type of
        structure is unsupported. We should fail with a CourseStructureError, as
        that will emit useful debug information.
        """
        # Course -> Section -> Unit (No Sequence)
        with self.store.bulk_operations(self.course_key):
            section_1 = ItemFactory.create(
                parent=self.draft_course,
                category='chapter',
                display_name="Section",
            )
            # This Unit should be skipped
            ItemFactory.create(parent=section_1,
                               category='vertical',
                               display_name="u1")
            ItemFactory.create(parent=section_1,
                               category='sequential',
                               display_name="standard_seq")
            ItemFactory.create(parent=section_1,
                               category='sequential',
                               display_name="pset_seq")
            ItemFactory.create(parent=section_1,
                               category='sequential',
                               display_name="video_seq")

            # This should work fine
            section_2 = ItemFactory.create(
                parent=self.draft_course,
                category='chapter',
                display_name="Section 2",
            )

            # Second error message here
            ItemFactory.create(parent=section_2,
                               category='vertical',
                               display_name="u2")

        outline, errs = get_outline_from_modulestore(self.course_key)
        assert len(outline.sections) == 2
        assert len(outline.sections[0].sequences) == 3
        assert len(outline.sections[1].sequences) == 0
        assert len(outline.sequences) == 3

        # Version-less usage keys
        unit_1_loc = self.course_key.make_usage_key('vertical', 'u1')
        unit_2_loc = self.course_key.make_usage_key('vertical', 'u2')
        assert errs[0].usage_key == unit_1_loc
        assert errs[1].usage_key == unit_2_loc