def test_amp_expand(self):
     """Test whether ampersand is not being expanded multiple times"""
     input_char = 'asd<>&'
     expected_output = 'asd&lt;&gt;&amp;'
     output = html_escape(input_char)
     self.assertEqual(output, expected_output)
     input_multi_char = 'asd<><>&&'
     expected_multi_output = 'asd&lt;&gt;&lt;&gt;&amp;&amp;'
     output_multi = html_escape(input_multi_char)
     self.assertEqual(output_multi, expected_multi_output)
    def create_xml_from_ini(self, ini_filepath, ini_content):
        """
        Creates group.xml file from INI file. All tags are replaced by function
        update_value_list. Function also checks whether check script fulfills
        all criteria

        @param {str} ini_filepath - real path of ini file
        @param {dict} ini_content - options and values from ini file:
            {option1: value, option2: value, ...}
        @throws {IOError}
        """
        self.select_rules.append(xml_tags.SELECT_TAG)
        update_fnc = {
            'config_file': self.fnc_config_file,
            'check_script': self.fnc_check_script,
            'check_description': self.fnc_check_description,
            'solution': self.fnc_solution_text,
            'content_title': self.update_text,
            'content_description': self.update_text,
        }
        ModuleHelper.check_required_fields(ini_filepath, ini_content)
        self.mh = ModuleHelper(os.path.dirname(ini_filepath))

        self.update_values_list(self.rule, "{rule_tag}",
                                ''.join(xml_tags.RULE_SECTION))
        value_tag, check_export_tag = self.add_value_tag()
        self.update_values_list(self.rule, "{check_export}",
                                ''.join(check_export_tag))
        self.update_values_list(self.rule, "{group_value}",
                                ''.join(value_tag))

        for k, function in iter(update_fnc.items()):
            try:
                function(ini_content, k)
            except IOError as e:
                err_msg = "Invalid value of the field '%s' in INI file" \
                          " '%s'\n'%s': %s\n" % (k, ini_filepath,
                                                 ini_content[k], e.strerror)
                raise IOError(err_msg)

        self.update_values_list(
            self.rule, '{group_title}',
            html_escape(ini_content['content_title'])
        )
        if 'mode' not in ini_content:
            self.fnc_update_mode('migrate, upgrade')
        else:
            self.fnc_update_mode(ini_content['mode'])
    def create_xml_from_ini(self, ini_filepath, ini_content):
        """
        Creates group.xml file from INI file. All tags are replaced by function
        update_value_list. Function also checks whether check script fulfills
        all criteria

        @param {str} ini_filepath - real path of ini file
        @param {dict} ini_content - options and values from ini file:
            {option1: value, option2: value, ...}
        @throws {IOError}
        """
        self.select_rules.append(xml_tags.SELECT_TAG)
        update_fnc = {
            'config_file': self.fnc_config_file,
            'check_script': self.fnc_check_script,
            'check_description': self.fnc_check_description,
            'solution': self.fnc_solution_text,
            'content_title': self.update_text,
            'content_description': self.update_text,
        }
        ModuleHelper.check_required_fields(ini_filepath, ini_content)
        self.mh = ModuleHelper(os.path.dirname(ini_filepath))

        self.update_values_list(self.rule, "{rule_tag}",
                                ''.join(xml_tags.RULE_SECTION))
        value_tag, check_export_tag = self.add_value_tag()
        self.update_values_list(self.rule, "{check_export}",
                                ''.join(check_export_tag))
        self.update_values_list(self.rule, "{group_value}", ''.join(value_tag))

        for k, function in iter(update_fnc.items()):
            try:
                function(ini_content, k)
            except IOError as e:
                err_msg = "Invalid value of the field '%s' in INI file" \
                          " '%s'\n'%s': %s\n" % (k, ini_filepath,
                                                 ini_content[k], e.strerror)
                raise IOError(err_msg)

        self.update_values_list(self.rule, '{group_title}',
                                html_escape(ini_content['content_title']))
        if 'mode' not in ini_content:
            self.fnc_update_mode('migrate, upgrade')
        else:
            self.fnc_update_mode(ini_content['mode'])
Ejemplo n.º 4
0
 def test_all(self):
     """Test if list of strings is escaped well"""
     tmp_input = "a<b>x'xyz&z"
     output = html_escape(tmp_input)
     expected_ouput = 'a&lt;b&gt;x&apos;xyz&amp;z'
     self.assertEqual(output, expected_ouput)
Ejemplo n.º 5
0
 def test_basic_string(self):
     """Test if single string is escaped well"""
     input_char = "asd < > &"
     expected_output = "asd &lt; &gt; &amp;"
     output = html_escape(input_char)
     self.assertEqual(output, expected_output)
 def test_all(self):
     """Test if list of strings is escaped well"""
     tmp_input = "a<b>x'xyz&z"
     output = html_escape(tmp_input)
     expected_ouput = 'a&lt;b&gt;x&apos;xyz&amp;z'
     self.assertEqual(output, expected_ouput)
 def test_basic_string(self):
     """Test if single string is escaped well"""
     input_char = "asd < > &"
     expected_output = "asd &lt; &gt; &amp;"
     output = html_escape(input_char)
     self.assertEqual(output, expected_output)
 def update_text(self, key, name):
     """Function updates a text."""
     if key[name] is not None:
         # escape values so they can be loaded as XMLs
         escaped_text = html_escape(key[name])
         self.update_values_list(self.rule, "{" + name + "}", escaped_text)
 def update_text(self, key, name):
     """Function updates a text."""
     if key[name] is not None:
         # escape values so they can be loaded as XMLs
         escaped_text = html_escape(key[name])
         self.update_values_list(self.rule, "{" + name + "}", escaped_text)
Ejemplo n.º 10
0
 def test_all(self):
     """Test if list of strings is escaped well"""
     tmp_input = ['a<', 'b>', "x'x", 'y"', 'z&z']
     output = html_escape(tmp_input)
     expected_ouput = ['a&lt;', 'b&gt;', 'x&apos;x', 'y&quot;', 'z&amp;z']
     self.assertEqual(output, expected_ouput)
Ejemplo n.º 11
0
 def test_basic(self):
     """Basic test with quotation"""
     input_char = ['asd', '<qwe>', "this 'is' quoted"]
     output = html_escape(input_char)
     expected_output = ['asd', '&lt;qwe&gt;', 'this &apos;is&apos; quoted']
     self.assertEqual(output, expected_output)