def update_text(self, key, name): """Function updates a text.""" try: if key[name] is not None: # escape values so they can be loaded as XMLs escaped_text = html_escape_string(key[name]) self.update_values_list(self.rule, "{"+name+"}", escaped_text) except KeyError: raise MissingTagsIniFileError
def update_text(self, key, name): """Function updates a text.""" try: if key[name] is not None: # escape values so they can be loaded as XMLs escaped_text = html_escape_string(key[name]) self.update_values_list(self.rule, "{" + name + "}", escaped_text) except KeyError: raise MissingTagsIniFileError
def create_xml_from_ini(self, main): """ The function creates group.xml file from INI file. All tag are replaced by function update_value_list Function also checks whether check script full fills all criteria """ 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, 'applies_to': self.dummy_fnc, 'binary_req': self.dummy_fnc, 'content_title': self.update_text, 'content_description': self.update_text, } for key in self.keys: self.check_recommended_fields(key, script_name=main) # Add solution text into value if 'solution' in key: xml_tags.DIC_VALUES['solution_file'] = key['solution'] else: xml_tags.DIC_VALUES['solution_file'] = 'solution.txt' # Add flag where will be shown content if in admin part or in user part if 'result_part' in key: xml_tags.DIC_VALUES['result_part'] = key['result_part'] else: xml_tags.DIC_VALUES['result_part'] = 'admin' 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)) try: for k, function in six.iteritems(update_fnc): try: function(key, k) except IOError as e: e_title = "Wrong value for tag '%s' in INI file '%s'\n" % (k, main) e_msg = "'%s': %s" % (key[k], e.strerror) print_error_msg(title=e_title, msg=e_msg) raise MissingTagsIniFileError except MissingTagsIniFileError: title = "Following tag '%s' is missing in INI File %s\n" % (k, main) print_error_msg(title=title) raise MissingTagsIniFileError self.update_values_list(self.rule, '{group_title}', html_escape_string(key['content_title'])) try: if 'mode' not in key: self.fnc_update_mode(key['check_script'], 'migrate, upgrade') else: self.fnc_update_mode(key['check_script'], key['mode']) except KeyError: pass
def test_basic_string(self): """Test if single string is escaped well""" input_char = "asd < > &" expected_output = "asd < > &" output = html_escape_string(input_char) self.assertEqual(output, expected_output)
def create_xml_from_ini(self, main): """ The function creates group.xml file from INI file. All tag are replaced by function update_value_list Function also checks whether check script full fills all criteria """ 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, 'applies_to': self.dummy_fnc, 'binary_req': self.dummy_fnc, 'content_title': self.update_text, 'content_description': self.update_text, } for key in self.keys: self.check_recommended_fields(key, script_name=main) # Add solution text into value if 'solution' in key: xml_tags.DIC_VALUES['solution_file'] = key['solution'] else: xml_tags.DIC_VALUES['solution_file'] = 'solution.txt' # Add flag where will be shown content if in admin part or in user part if 'result_part' in key: xml_tags.DIC_VALUES['result_part'] = key['result_part'] else: xml_tags.DIC_VALUES['result_part'] = 'admin' 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)) try: for k, function in six.iteritems(update_fnc): try: function(key, k) except IOError as e: e_title = "Wrong value for tag '%s' in INI file '%s'\n" % ( k, main) e_msg = "'%s': %s" % (key[k], e.strerror) print_error_msg(title=e_title, msg=e_msg) raise MissingTagsIniFileError except MissingTagsIniFileError: title = "Following tag '%s' is missing in INI File %s\n" % ( k, main) print_error_msg(title=title) raise MissingTagsIniFileError self.update_values_list(self.rule, '{group_title}', html_escape_string(key['content_title'])) try: if 'mode' not in key: self.fnc_update_mode(key['check_script'], 'migrate, upgrade') else: self.fnc_update_mode(key['check_script'], key['mode']) except KeyError: pass