def _GetProcessedAction(self, owner, description, obsolete, not_user_triggered=NO_VALUE, new_actions=[], comment=NO_VALUE): """Forms an actions XML string and returns it after processing. It parses the original XML string, adds new user actions (if there is any), and pretty prints it. Args: owner: the owner tag to be inserted in the original XML string. description: the description tag to be inserted in the original XML string. obsolete: the obsolete tag to be inserted in the original XML string. new_actions: optional. List of new user actions' names to be inserted. comment: the comment tag to be inserted in the original XML string. Returns: An updated and pretty-printed action XML string. """ # Form the actions.xml mock content based on the input parameters. current_xml = ACTIONS_XML.format(owners=owner, description=description, obsolete=obsolete, comment=comment, not_user_triggered=not_user_triggered) actions, actions_dict, comments = extract_actions.ParseActionFile( current_xml) for new_action in new_actions: actions.add(new_action) return extract_actions.PrettyPrint(actions, actions_dict, comments)
def testTwoObsoletes(self): current_xml = ACTIONS_XML.format(owners=TWO_OWNERS, obsolete=TWO_OBSOLETE, description=DESCRIPTION, comment=NO_VALUE, not_user_triggered=NO_VALUE) # Since there are two obsolete tags, the function ParseActionFile will # raise SystemExit with exit code 1. with self.assertRaises(SystemExit) as cm: _, _ = extract_actions.ParseActionFile(current_xml) self.assertEqual(cm.exception.code, 1)
def _GetProcessedActionFromActionsXMLString(self, actions_xml): """parses the given actions XML string and pretty prints it. Args: actions_xml: actions XML string. Returns: An updated and pretty-printed actions XML string. """ actions, actions_dict, comments = extract_actions.ParseActionFile( actions_xml) return extract_actions.PrettyPrint(actions, actions_dict, comments)
def _PrettyPrintActionsXML(self, actions_xml): """Parses the given actions XML and pretty prints it. Args: actions_xml: actions XML string. Returns: A pretty-printed actions XML string. """ actions_dict, comments, suffixes = extract_actions.ParseActionFile( actions_xml) return extract_actions.PrettyPrint(actions_dict, comments, suffixes)
def testErrorSuffixNameMissing(self): original_xml = """ <actions> <action name="action1"> <owner>[email protected]</owner> <description>Description.</description> </action> <action-suffix> <suffix label="Suffix Description 1." /> <affected-action name="action1" /> </action-suffix> </actions> """ with self.assertRaises(action_utils.SuffixNameEmptyError) as cm: extract_actions.ParseActionFile(original_xml)
def testErrorBadActionName(self): original_xml = """ <actions> <action name="action1"> <owner>[email protected]</owner> <description>Description.</description> </action> <action-suffix ordering="prefix"> <suffix name="prefix1" label="Prefix Description 1." /> <affected-action name="action1" /> </action-suffix> </actions> """ with self.assertRaises(action_utils.InvalidAffecteddActionNameError) as cm: extract_actions.ParseActionFile(original_xml)
def _ExpandSuffixesInActionsXML(self, actions_xml): """Parses the given actions XML, expands suffixes and pretty prints it. Args: actions_xml: actions XML string. Returns: An updated and pretty-printed actions XML string with suffixes expanded. """ actions_dict, comments, suffixes = extract_actions.ParseActionFile( actions_xml) # Clear suffixes and mark actions as not coming from suffixes, so that # the returned XML file is the expanded one. suffixes = [] for action in actions_dict.itervalues(): action.from_suffix = False return extract_actions.PrettyPrint(actions_dict, comments, suffixes)
def testErrorBadActionName(self): original_xml = """ <actions> <action name="action1"> <owner>[email protected]</owner> <description>Description.</description> </action> <actions-suffixes> <action-suffix ordering='prefix'> <suffix name="prefix1" label="Prefix Description 1." /> <affected-action name="action1" /> </action-suffix> </actions-suffixes> </actions> """ with self.assertRaises(SystemExit) as cm: extract_actions.ParseActionFile(original_xml) self.assertEqual(cm.exception.code, 1)