Beispiel #1
0
    def map(item):
        if item.deleted:
            return

        exploration = exp_services.get_exploration_from_model(item)

        html_list = exploration.get_all_html_content_strings()

        err_dict = html_validation_service.validate_rte_format(
            html_list, feconf.RTE_FORMAT_CKEDITOR)

        for key in err_dict:
            if err_dict[key]:
                yield (key, err_dict[key])
Beispiel #2
0
    def map(item):
        if item.deleted:
            return

        try:
            exploration = exp_fetchers.get_exploration_from_model(item)
        except Exception as e:
            yield ('Error %s when loading exploration' % str(e), [item.id])
            return

        html_list = exploration.get_all_html_content_strings()

        err_dict = html_validation_service.validate_rte_format(
            html_list, feconf.RTE_FORMAT_CKEDITOR)

        for key in err_dict:
            if err_dict[key]:
                yield ('%s Exp Id: %s' % (key, item.id), err_dict[key])
    def map(item):
        if item.deleted:
            return
        err_dict = {}

        try:
            exploration = exp_services.get_exploration_from_model(item)
        except Exception as e:
            yield ('Error %s when loading exploration' % str(e), [item.id])
            return

        html_list = exploration.get_all_html_content_strings()
        try:
            err_dict = html_validation_service.validate_rte_format(
                html_list, feconf.RTE_FORMAT_CKEDITOR, run_migration=True)
        except Exception as e:
            yield ('Error in validating rte format for exploration %s' %
                   item.id, [traceback.format_exc()])
            return

        for key in err_dict:
            if err_dict[key]:
                yield (key, err_dict[key])
    def test_validate_rte_format(self):
        test_cases_for_textangular = [
            ('This is for <i>testing</i> the validate <b>text</b> '
             'angular function.'),
            ('This is the last test case <a href="https://github.com">hello'
             '<oppia-noninteractive-link url-with-value="&amp;quot;'
             'here&amp;quot;" text-with-value="validated">'
             '</oppia-noninteractive-link></a><p> testing completed</p>')
        ]
        actual_output_with_migration_for_textangular = (
            html_validation_service.validate_rte_format(
                test_cases_for_textangular,
                feconf.RTE_FORMAT_TEXTANGULAR,
                run_migration=True))
        actual_output_without_migration_for_textangular = (
            html_validation_service.validate_rte_format(
                test_cases_for_textangular, feconf.RTE_FORMAT_TEXTANGULAR))

        expected_output_with_migration_for_textangular = {'strings': []}
        expected_output_without_migration_for_textangular = {
            'i': ['[document]'],
            'invalidTags': ['a'],
            'oppia-noninteractive-link': ['a'],
            'b': ['[document]'],
            'strings': [
                ('This is for <i>testing</i> the validate '
                 '<b>text</b> angular function.'),
                ('This is the last test case <a href="https://github.com">'
                 'hello<oppia-noninteractive-link url-with-value="&amp;'
                 'quot;here&amp;quot;" text-with-value="validated">'
                 '</oppia-noninteractive-link></a><p> testing completed</p>'),
            ]
        }

        self.assertEqual(actual_output_with_migration_for_textangular,
                         expected_output_with_migration_for_textangular)
        self.assertEqual(actual_output_without_migration_for_textangular,
                         expected_output_without_migration_for_textangular)

        test_cases_for_ckeditor = [
            ('<pre>Hello this is <b> testing '
             '<oppia-noninteractive-image filepath-with-value="amp;quot;'
             'random.png&amp;quot;"></oppia-noninteractive-image> in '
             '</b>progress</pre>'),
            ('<oppia-noninteractive-collapsible content-with-value="&amp;'
             'quot;&amp;lt;pre&amp;gt;&amp;lt;p&amp;gt;lorem ipsum&amp;'
             'lt;/p&amp;gt;&amp;lt;/pre&amp;gt;'
             '&amp;quot;" heading-with-value="&amp;quot;'
             'lorem ipsum&amp;quot;lorem ipsum&amp;quot;?&amp;quot;">'
             '</oppia-noninteractive-collapsible>')
        ]

        actual_output_with_migration_for_ckeditor = (
            html_validation_service.validate_rte_format(
                test_cases_for_ckeditor,
                feconf.RTE_FORMAT_CKEDITOR,
                run_migration=True))
        actual_output_without_migration_for_ckeditor = (
            html_validation_service.validate_rte_format(
                test_cases_for_ckeditor, feconf.RTE_FORMAT_CKEDITOR))

        expected_output_with_migration_for_ckeditor = {'strings': []}
        expected_output_without_migration_for_ckeditor = {
            'invalidTags': ['b'],
            'oppia-noninteractive-image': ['b'],
            'p': ['pre'],
            'strings': [
                ('<pre>Hello this is <b> testing '
                 '<oppia-noninteractive-image filepath-with-value="amp;quot;'
                 'random.png&amp;quot;"></oppia-noninteractive-image> in '
                 '</b>progress</pre>'),
                ('<oppia-noninteractive-collapsible content-with-value="&amp'
                 ';quot;&amp;lt;pre&amp;gt;&amp;lt;p&amp;gt;lorem ipsum&amp;'
                 'lt;/p&amp;gt;&amp;lt;/pre&amp;gt;'
                 '&amp;quot;" heading-with-value="&amp;quot;'
                 'lorem ipsum&amp;quot;lorem ipsum&amp;quot;?&amp;quot;">'
                 '</oppia-noninteractive-collapsible>'),
            ]
        }

        self.assertEqual(actual_output_with_migration_for_ckeditor,
                         expected_output_with_migration_for_ckeditor)
        self.assertEqual(actual_output_without_migration_for_ckeditor,
                         expected_output_without_migration_for_ckeditor)