Ejemplo n.º 1
0
    def setUp(self):
        super(TestConditionalContentAccess, self).setUp()

        # Add a verified mode to the course
        CourseModeFactory.create(course_id=self.course.id, mode_slug='audit')
        CourseModeFactory.create(course_id=self.course.id,
                                 mode_slug='verified')

        # Create variables that more accurately describe the student's function
        self.student_audit_a = self.student_a
        self.student_audit_b = self.student_b

        # Create verified students
        self.student_verified_a = UserFactory.create(
            username='******',
            email='*****@*****.**')
        CourseEnrollmentFactory.create(user=self.student_verified_a,
                                       course_id=self.course.id,
                                       mode='verified')
        self.student_verified_b = UserFactory.create(
            username='******',
            email='*****@*****.**')
        CourseEnrollmentFactory.create(user=self.student_verified_b,
                                       course_id=self.course.id,
                                       mode='verified')

        # Put students into content gating groups
        UserCourseTagFactory(
            user=self.student_verified_a,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(
                self.partition.id),
            value=str('0'),
        )
        UserCourseTagFactory(
            user=self.student_verified_b,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(
                self.partition.id),
            value=str('1'),
        )
        # Create blocks to go into the verticals
        self.block_a = ItemFactory.create(
            category='problem',
            parent=self.vertical_a,
            display_name='problem_a',
            metadata=METADATA,
        )
        self.block_b = ItemFactory.create(
            category='problem',
            parent=self.vertical_b,
            display_name='problem_b',
            metadata=METADATA,
        )
Ejemplo n.º 2
0
    def _check_split_test(self, user_tag):
        """Checks that the right compentents are rendered for user with ``user_tag``"""
        # This explicitly sets the user_tag for self.student to ``user_tag``
        UserCourseTagFactory(
            user=self.student,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(self.partition.id),
            value=str(user_tag)
        )

        resp = self.client.get(reverse(
            'courseware_section',
            kwargs={'course_id': self.course.id.to_deprecated_string(),
                    'chapter': self.chapter.url_name,
                    'section': self.sequential.url_name}
        ))
        content = resp.content

        # Assert we see the proper icon in the top display
        self.assertIn('<a class="{} inactive progress-0"'.format(self.ICON_CLASSES[user_tag]), content)
        # And proper tooltips
        for tooltip in self.TOOLTIPS[user_tag]:
            self.assertIn(tooltip, content)

        for hidden in self.HIDDEN_CONTENT[user_tag]:
            self.assertNotIn(hidden, content)

        # Assert that we can see the data from the appropriate test condition
        for visible in self.VISIBLE_CONTENT[user_tag]:
            self.assertIn(visible, content)
Ejemplo n.º 3
0
    def _check_split_test(self, user_tag):
        """Checks that the right compentents are rendered for user with ``user_tag``"""
        # This explicitly sets the user_tag for self.student to ``user_tag``
        UserCourseTagFactory(
            user=self.student,
            course_id=self.course.id,
            key=f'xblock.partition_service.partition_{self.partition.id}',
            value=str(user_tag))

        resp = self.client.get(
            reverse('courseware_section',
                    kwargs={
                        'course_id': str(self.course.id),
                        'chapter': self.chapter.url_name,
                        'section': self.sequential.url_name
                    }))
        unicode_content = resp.content.decode(resp.charset)

        # Assert we see the proper icon in the top display
        assert f'<button class="{self.ICON_CLASSES[user_tag]} inactive nav-item tab"' in unicode_content

        # And proper tooltips
        for tooltip in self.TOOLTIPS[user_tag]:
            assert tooltip in unicode_content

        for key in self.included_usage_keys[user_tag]:
            assert str(key) in unicode_content

        for key in self.excluded_usage_keys[user_tag]:
            assert str(key) not in unicode_content

        # Assert that we can see the data from the appropriate test condition
        for visible in self.VISIBLE_CONTENT[user_tag]:
            assert visible in unicode_content
    def split_setup(self, user_partition_group):
        """
        Setup for tests using split_test module. Creates a split_test instance as a child of self.homework_conditional
        with 2 verticals in it, and assigns self.student_user to the specified user_partition_group.

        The verticals are returned.
        """
        vertical_0_url = self.course.id.make_usage_key(
            "vertical", "split_test_vertical_0")
        vertical_1_url = self.course.id.make_usage_key(
            "vertical", "split_test_vertical_1")

        group_id_to_child = {}
        for index, url in enumerate([vertical_0_url, vertical_1_url]):
            group_id_to_child[str(index)] = url

        split_test = ItemFactory.create(
            parent_location=self.homework_conditional.location,
            category="split_test",
            display_name="Split test",
            user_partition_id='0',
            group_id_to_child=group_id_to_child,
        )

        vertical_0 = ItemFactory.create(
            parent_location=split_test.location,
            category="vertical",
            display_name="Condition 0 vertical",
            location=vertical_0_url,
        )

        vertical_1 = ItemFactory.create(
            parent_location=split_test.location,
            category="vertical",
            display_name="Condition 1 vertical",
            location=vertical_1_url,
        )

        # Now add the student to the specified group.
        UserCourseTagFactory(
            user=self.student_user,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(
                self.partition.id),
            value=str(user_partition_group))

        return vertical_0, vertical_1
Ejemplo n.º 5
0
 def test_welcome_message(self, welcome_message_is_dismissed):
     CourseEnrollment.enroll(self.user, self.course.id)
     self.store.create_item(self.user.id,
                            self.course.id,
                            'course_info',
                            'updates',
                            fields={
                                'items': [{
                                    'content': '<p>Welcome</p>',
                                    'status': 'visible',
                                    'date': 'July 23, 2020',
                                    'id': 1
                                }]
                            })
     UserCourseTagFactory(user=self.user,
                          course_id=self.course.id,
                          key='view-welcome-message',
                          value=not welcome_message_is_dismissed)
     welcome_message_html = self.client.get(
         self.url).data['welcome_message_html']
     assert welcome_message_html == (None if welcome_message_is_dismissed
                                     else '<p>Welcome</p>')
Ejemplo n.º 6
0
    def setUp(self):
        """
        Set up a course with graded problems within a split test.

        Course hierarchy is as follows (modeled after how split tests
        are created in studio):
        -> course
            -> chapter
                -> sequential (graded)
                    -> vertical
                        -> split_test
                            -> vertical (Group A)
                                -> problem
                            -> vertical (Group B)
                                -> problem
        """
        super(TestConditionalContent, self).setUp()

        # Create user partitions
        self.user_partition_group_a = 0
        self.user_partition_group_b = 1
        self.partition = UserPartition(
            0, 'first_partition', 'First Partition', [
                Group(self.user_partition_group_a, 'Group A'),
                Group(self.user_partition_group_b, 'Group B')
            ])

        # Create course with group configurations and grading policy
        self.course = CourseFactory.create(user_partitions=[self.partition],
                                           grading_policy={
                                               "GRADER": [{
                                                   "type": "Homework",
                                                   "min_count": 1,
                                                   "drop_count": 0,
                                                   "short_label": "HW",
                                                   "weight": 1.0
                                               }]
                                           })
        chapter = ItemFactory.create(parent_location=self.course.location,
                                     display_name='Chapter')

        # add a sequence to the course to which the problems can be added
        self.problem_section = ItemFactory.create(
            parent_location=chapter.location,
            category='sequential',
            metadata={
                'graded': True,
                'format': 'Homework'
            },
            display_name=self.TEST_SECTION_NAME)

        # Create users and partition them
        self.student_a = UserFactory.create(
            username='******', email='student_a@contrived_example.com')
        CourseEnrollmentFactory.create(user=self.student_a,
                                       course_id=self.course.id)
        self.student_b = UserFactory.create(
            username='******', email='student_b@contrived_example.com')
        CourseEnrollmentFactory.create(user=self.student_b,
                                       course_id=self.course.id)

        UserCourseTagFactory(
            user=self.student_a,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(
                self.partition.id),
            value=str(self.user_partition_group_a))
        UserCourseTagFactory(
            user=self.student_b,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(
                self.partition.id),
            value=str(self.user_partition_group_b))

        # Create a vertical to contain our split test
        problem_vertical = ItemFactory.create(
            parent_location=self.problem_section.location,
            category='vertical',
            display_name='Problem Unit')

        # Create the split test and child vertical containers
        vertical_a_url = self.course.id.make_usage_key(
            'vertical', 'split_test_vertical_a')
        vertical_b_url = self.course.id.make_usage_key(
            'vertical', 'split_test_vertical_b')
        self.split_test = ItemFactory.create(
            parent_location=problem_vertical.location,
            category='split_test',
            display_name='Split Test',
            user_partition_id=self.partition.id,
            group_id_to_child={
                str(index): url
                for index, url in enumerate([vertical_a_url, vertical_b_url])
            })
        self.vertical_a = ItemFactory.create(
            parent_location=self.split_test.location,
            category='vertical',
            display_name='Group A problem container',
            location=vertical_a_url)
        self.vertical_b = ItemFactory.create(
            parent_location=self.split_test.location,
            category='vertical',
            display_name='Group B problem container',
            location=vertical_b_url)
Ejemplo n.º 7
0
    def setUp(self):
        """
        Set up a course with graded problems within a split test.

        Course hierarchy is as follows (modeled after how split tests
        are created in studio):
        -> course
            -> chapter
                -> sequential (graded)
                    -> vertical
                        -> split_test
                            -> vertical (Group A)
                                -> problem
                            -> vertical (Group B)
                                -> problem
        """
        super(TestGradeReportConditionalContent, self).setUp()

        # Create user partitions
        self.user_partition_group_a = 0
        self.user_partition_group_b = 1
        self.partition = UserPartition(
            0, 'first_partition', 'First Partition', [
                Group(self.user_partition_group_a, 'Group A'),
                Group(self.user_partition_group_b, 'Group B')
            ])

        # Create course with group configurations and grading policy
        self.initialize_course(
            course_factory_kwargs={
                'user_partitions': [self.partition],
                'grading_policy': {
                    "GRADER": [{
                        "type": "Homework",
                        "min_count": 1,
                        "drop_count": 0,
                        "short_label": "HW",
                        "weight": 1.0
                    }]
                }
            })

        # Create users and partition them
        self.student_a = self.create_student('student_a')
        self.student_b = self.create_student('student_b')
        UserCourseTagFactory(
            user=self.student_a,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(
                self.partition.id),  # pylint: disable=no-member
            value=str(self.user_partition_group_a))
        UserCourseTagFactory(
            user=self.student_b,
            course_id=self.course.id,
            key='xblock.partition_service.partition_{0}'.format(
                self.partition.id),  # pylint: disable=no-member
            value=str(self.user_partition_group_b))

        # Create a vertical to contain our split test
        problem_vertical = ItemFactory.create(
            parent_location=self.problem_section.location,
            category='vertical',
            display_name='Problem Unit')

        # Create the split test and child vertical containers
        vertical_a_url = self.course.id.make_usage_key(
            'vertical', 'split_test_vertical_a')
        vertical_b_url = self.course.id.make_usage_key(
            'vertical', 'split_test_vertical_b')
        self.split_test = ItemFactory.create(
            parent_location=problem_vertical.location,
            category='split_test',
            display_name='Split Test',
            user_partition_id=self.partition.id,  # pylint: disable=no-member
            group_id_to_child={
                str(index): url
                for index, url in enumerate([vertical_a_url, vertical_b_url])
            })
        self.vertical_a = ItemFactory.create(
            parent_location=self.split_test.location,
            category='vertical',
            display_name='Group A problem container',
            location=vertical_a_url)
        self.vertical_b = ItemFactory.create(
            parent_location=self.split_test.location,
            category='vertical',
            display_name='Group B problem container',
            location=vertical_b_url)