示例#1
0
    def test_preview_no_asides(self):
        """
        Test for calling get_preview_html. Ensures data-usage-id is correctly set and
        asides are correctly excluded because they are not enabled.
        """
        course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
        html = ItemFactory.create(parent_location=course.location,
                                  category="html",
                                  data={'data': "<html>foobar</html>"})

        config = StudioConfig.current()
        config.enabled = False
        config.save()

        request = RequestFactory().get('/dummy-url')
        request.user = UserFactory()
        request.session = {}

        # Call get_preview_fragment directly.
        context = {'reorderable_items': set(), 'read_only': True}
        html = get_preview_fragment(request, html, context).content

        self.assertNotRegexpMatches(html,
                                    r"data-block-type=[\"\']test_aside[\"\']")
        self.assertNotRegexpMatches(html, "Aside rendered")
示例#2
0
    def test_preview_no_asides(self):
        """
        Test for calling get_preview_html. Ensures data-usage-id is correctly set and
        asides are correctly excluded because they are not enabled.
        """
        course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
        html = ItemFactory.create(
            parent_location=course.location,
            category="html",
            data={'data': "<html>foobar</html>"}
        )

        config = StudioConfig.current()
        config.enabled = False
        config.save()

        request = RequestFactory().get('/dummy-url')
        request.user = UserFactory()
        request.session = {}

        # Call get_preview_fragment directly.
        context = {
            'reorderable_items': set(),
            'read_only': True
        }
        html = get_preview_fragment(request, html, context).content

        self.assertNotRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']")
        self.assertNotRegexpMatches(html, "Aside rendered")
示例#3
0
 def applicable_aside_types(self, block):
     """
     Remove acid_aside and honor the config record
     """
     if not StudioConfig.asides_enabled(block.scope_ids.block_type):
         return []
     return [
         aside_type for aside_type in super(
             PreviewModuleSystem, self).applicable_aside_types(block)
         if aside_type != 'acid_aside'
     ]
示例#4
0
 def applicable_aside_types(self, block):
     """
     Remove acid_aside and honor the config record
     """
     if not StudioConfig.asides_enabled(block.scope_ids.block_type):
         return []
     return [
         aside_type
         for aside_type in super(PreviewModuleSystem, self).applicable_aside_types(block)
         if aside_type != 'acid_aside'
     ]
示例#5
0
    def applicable_aside_types(self, block):
        """
        Remove acid_aside and honor the config record
        """
        if not StudioConfig.asides_enabled(block.scope_ids.block_type):
            return []

        # TODO: aside_type != 'acid_aside' check should be removed once AcidBlock is only installed during tests
        # (see https://openedx.atlassian.net/browse/TE-811)
        return [
            aside_type for aside_type in super().applicable_aside_types(block)
            if aside_type != 'acid_aside'
        ]
示例#6
0
    def applicable_aside_types(self, block):
        """
        Remove acid_aside and honor the config record
        """
        if not StudioConfig.asides_enabled(block.scope_ids.block_type):
            return []

        # TODO: aside_type != 'acid_aside' check should be removed once AcidBlock is only installed during tests
        # (see https://openedx.atlassian.net/browse/TE-811)
        return [
            aside_type for aside_type in super(
                PreviewModuleSystem, self).applicable_aside_types(block)  # lint-amnesty, pylint: disable=super-with-arguments
            if aside_type != 'acid_aside'
        ]
示例#7
0
    def test_preview_fragment(self):
        """
        Test for calling get_preview_html. Ensures data-usage-id is correctly set and
        asides are correctly included.
        """
        course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
        html = ItemFactory.create(
            parent_location=course.location,
            category="html",
            data={'data': "<html>foobar</html>"}
        )

        config = StudioConfig.current()
        config.enabled = True
        config.save()

        request = RequestFactory().get('/dummy-url')
        request.user = UserFactory()
        request.session = {}

        # Call get_preview_fragment directly.
        context = {
            'reorderable_items': set(),
            'read_only': True
        }
        html = get_preview_fragment(request, html, context).content

        # Verify student view html is returned, and the usage ID is as expected.
        html_pattern = re.escape(
            str(course.id.make_usage_key('html', 'replaceme'))
        ).replace('replaceme', r'html_[0-9]*')
        self.assertRegex(
            html,
            f'data-usage-id="{html_pattern}"'
        )
        self.assertRegex(html, '<html>foobar</html>')
        self.assertRegex(html, r"data-block-type=[\"\']test_aside[\"\']")
        self.assertRegex(html, "Aside rendered")
        # Now ensure the acid_aside is not in the result
        self.assertNotRegex(html, r"data-block-type=[\"\']acid_aside[\"\']")

        # Ensure about pages don't have asides
        about = modulestore().get_item(course.id.make_usage_key('about', 'overview'))
        html = get_preview_fragment(request, about, context).content
        self.assertNotRegex(html, r"data-block-type=[\"\']test_aside[\"\']")
        self.assertNotRegex(html, "Aside rendered")
示例#8
0
    def test_preview_fragment(self):
        """
        Test for calling get_preview_html. Ensures data-usage-id is correctly set and
        asides are correctly included.
        """
        course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
        html = ItemFactory.create(
            parent_location=course.location,
            category="html",
            data={'data': "<html>foobar</html>"}
        )

        config = StudioConfig.current()
        config.enabled = True
        config.save()

        request = RequestFactory().get('/dummy-url')
        request.user = UserFactory()
        request.session = {}

        # Call get_preview_fragment directly.
        context = {
            'reorderable_items': set(),
            'read_only': True
        }
        html = get_preview_fragment(request, html, context).content

        # Verify student view html is returned, and the usage ID is as expected.
        html_pattern = re.escape(unicode(course.id.make_usage_key('html', 'replaceme'))).replace('replaceme', r'html_[0-9]*')
        self.assertRegexpMatches(
            html,
            'data-usage-id="{}"'.format(html_pattern)
        )
        self.assertRegexpMatches(html, '<html>foobar</html>')
        self.assertRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']")
        self.assertRegexpMatches(html, "Aside rendered")
        # Now ensure the acid_aside is not in the result
        self.assertNotRegexpMatches(html, r"data-block-type=[\"\']acid_aside[\"\']")

        # Ensure about pages don't have asides
        about = modulestore().get_item(course.id.make_usage_key('about', 'overview'))
        html = get_preview_fragment(request, about, context).content
        self.assertNotRegexpMatches(html, r"data-block-type=[\"\']test_aside[\"\']")
        self.assertNotRegexpMatches(html, "Aside rendered")
示例#9
0
    def setUp(self):
        """
        Preparation for the test execution
        """
        super().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()