Пример #1
0
 def test_substitution_without_anonymous_student_id(self):
     sample_xml = '''%%USER_ID%%'''
     module_data = {'data': sample_xml}
     module_system = test_system()
     module_system.anonymous_student_id = None
     module = HtmlModule(module_system, self.location, self.descriptor, module_data)
     self.assertEqual(module.get_html(), sample_xml)
Пример #2
0
 def test_substitution_without_anonymous_student_id(self):
     sample_xml = '''%%USER_ID%%'''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module_system.anonymous_student_id = None
     module = HtmlModule(self.descriptor, module_system, field_data, Mock())
     self.assertEqual(module.get_html(), sample_xml)
Пример #3
0
 def test_substitution_works(self):
     sample_xml = '''%%USER_ID%%'''
     module_data = {'data': sample_xml}
     module_system = get_test_system()
     module = HtmlModule(module_system, self.descriptor, module_data)
     self.assertEqual(module.get_html(),
                      str(module_system.anonymous_student_id))
Пример #4
0
 def test_substitution_without_anonymous_student_id(self):
     sample_xml = '''%%USER_ID%%'''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module_system.anonymous_student_id = None
     module = HtmlModule(self.descriptor, module_system, field_data, Mock())
     self.assertEqual(module.get_html(), sample_xml)
Пример #5
0
 def test_substitution_without_magic_string(self):
     sample_xml = '''
         <html>
             <p>Hi USER_ID!11!</p>
         </html>
     '''
     module_data = {'data': sample_xml}
     module = HtmlModule(test_system(), self.location, self.descriptor, module_data)
     self.assertEqual(module.get_html(), sample_xml)
Пример #6
0
 def test_substitution_without_magic_string(self):
     sample_xml = '''
         <html>
             <p>Hi USER_ID!11!</p>
         </html>
     '''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module = HtmlModule(self.descriptor, module_system, field_data, Mock())
     self.assertEqual(module.get_html(), sample_xml)
Пример #7
0
 def test_substitution_without_magic_string(self):
     sample_xml = '''
         <html>
             <p>Hi USER_ID!11!</p>
         </html>
     '''
     field_data = DictFieldData({'data': sample_xml})
     module_system = get_test_system()
     module = HtmlModule(self.descriptor, module_system, field_data, Mock())
     self.assertEqual(module.get_html(), sample_xml)
Пример #8
0
    def test_substitution_works(self):
        sample_xml = '''%%USER_ID%%'''
        field_data = DictFieldData({'data': sample_xml})
        anon_id = '123456789'

        module_system = get_test_system()
        module_system.substitute_keywords_with_data = Mock(return_value=anon_id)
        module = HtmlModule(self.descriptor, module_system, field_data, Mock())
        with patch('xmodule.html_module.get_default_time_display') as mock_get_default_time_display:
            mock_get_default_time_display.return_value = u''
            self.assertEqual(module.get_html(), anon_id)
Пример #9
0
    def test_substitution_works(self):
        sample_xml = '''%%USER_ID%%'''
        field_data = DictFieldData({'data': sample_xml})
        anon_id = '123456789'

        module_system = get_test_system()
        module_system.substitute_keywords_with_data = Mock(
            return_value=anon_id)
        module = HtmlModule(self.descriptor, module_system, field_data, Mock())
        with patch('xmodule.html_module.get_default_time_display'
                   ) as mock_get_default_time_display:
            mock_get_default_time_display.return_value = u''
            self.assertEqual(module.get_html(), anon_id)
Пример #10
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))
Пример #11
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"]',
            ))
Пример #12
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))
Пример #13
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"]',
            ))
Пример #14
0
 def test_student_preview_view(self, view):
     """
     Ensure that student_view and public_view renders correctly.
     """
     html = '<p>This is a test</p>'
     descriptor = Mock()
     field_data = DictFieldData({'data': html})
     module_system = get_test_system()
     module = HtmlModule(descriptor, module_system, field_data, Mock())
     rendered = module_system.render(module, view, {}).content
     self.assertIn(html, rendered)
Пример #15
0
 def test_substitution_works(self):
     sample_xml = '''%%USER_ID%%'''
     module_data = {'data': sample_xml}
     module_system = get_test_system()
     module = HtmlModule(module_system, self.descriptor, module_data)
     self.assertEqual(module.get_html(), str(module_system.anonymous_student_id))
Пример #16
0
 def test_substitution_works(self):
     sample_xml = """%%USER_ID%%"""
     field_data = DictFieldData({"data": sample_xml})
     module_system = get_test_system()
     module = HtmlModule(self.descriptor, module_system, field_data, Mock())
     self.assertEqual(module.get_html(), str(module_system.anonymous_student_id))