def test_common_values(self, html):
        """
        Ensure that student_view_data will return HTML data when enabled,
        can handle likely input,
        and doesn't modify the HTML in any way.

        This means that it does NOT protect against XSS, escape HTML tags, etc.

        Note that the %%USER_ID%% substitution is tested below.
        """
        descriptor = Mock()
        field_data = DictFieldData({'data': html})
        module_system = get_test_system()
        module = HtmlModule(descriptor, module_system, field_data, Mock())
        self.assertEqual(module.student_view_data(), dict(enabled=True, html=html))
Exemple #2
0
    def test_common_values(self, html):
        """
        Ensure that student_view_data will return HTML data when enabled,
        can handle likely input,
        and doesn't modify the HTML in any way.

        This means that it does NOT protect against XSS, escape HTML tags, etc.

        Note that the %%USER_ID%% substitution is tested below.
        """
        descriptor = Mock()
        field_data = DictFieldData({'data': html})
        module_system = get_test_system()
        module = HtmlModule(descriptor, module_system, field_data, Mock())
        self.assertEqual(module.student_view_data(), dict(enabled=True, html=html))
    def test_disabled(self, settings):
        """
        Ensure that student_view_data does not return html if the ENABLE_HTML_XBLOCK_STUDENT_VIEW_DATA feature flag
        is not set.
        """
        descriptor = Mock()
        field_data = DictFieldData({'data': '<h1>Some HTML</h1>'})
        module_system = get_test_system()
        module = HtmlModule(descriptor, module_system, field_data, Mock())

        with override_settings(**settings):
            self.assertEqual(module.student_view_data(), dict(
                enabled=False,
                message='To enable, set FEATURES["ENABLE_HTML_XBLOCK_STUDENT_VIEW_DATA"]',
            ))
Exemple #4
0
    def test_disabled(self, settings):
        """
        Ensure that student_view_data does not return html if the ENABLE_HTML_XBLOCK_STUDENT_VIEW_DATA feature flag
        is not set.
        """
        descriptor = Mock()
        field_data = DictFieldData({'data': '<h1>Some HTML</h1>'})
        module_system = get_test_system()
        module = HtmlModule(descriptor, module_system, field_data, Mock())

        with override_settings(**settings):
            self.assertEqual(module.student_view_data(), dict(
                enabled=False,
                message='To enable, set FEATURES["ENABLE_HTML_XBLOCK_STUDENT_VIEW_DATA"]',
            ))