def get_all_recipients(alert): """ Returns list of all recipient of specified alert. Format: [ { "id": <id of recipient>, "value": <value of recipient>, "description": <recipient description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs> } ] alert -- parent element of recipients to return """ recipient_list = [] for recipient in alert.findall("./recipient"): recipient_list.append({ "id": recipient.get("id"), "value": recipient.get("value"), "description": recipient.get("description", ""), "instance_attributes": get_nvset( get_sub_element(recipient, "instance_attributes") ), "meta_attributes": get_nvset( get_sub_element(recipient, "meta_attributes") ) }) return recipient_list
def get_all_alerts(tree): """ Returns list of all alerts specified in tree. Format: [ { "id": <id of alert>, "path": <path to script>, "description": <alert description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs>, "recipients_list": <list of alert's recipients> } ] tree -- cib etree node """ alert_list = [] for alert in get_alerts(tree).findall("./alert"): alert_list.append({ "id": alert.get("id"), "path": alert.get("path"), "description": alert.get("description", ""), "instance_attributes": get_nvset( get_sub_element(alert, "instance_attributes") ), "meta_attributes": get_nvset( get_sub_element(alert, "meta_attributes") ), "recipient_list": get_all_recipients(alert) }) return alert_list
def get_all_alerts(tree): """ Returns list of all alerts specified in tree. Format: [ { "id": <id of alert>, "path": <path to script>, "description": <alert description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs>, "recipients_list": <list of alert's recipients> } ] tree -- cib etree node """ alert_list = [] for alert in get_alerts(tree).findall("./alert"): alert_list.append({ "id": alert.get("id"), "path": alert.get("path"), "description": alert.get("description", ""), "instance_attributes": get_nvset(get_sub_element(alert, "instance_attributes")), "meta_attributes": get_nvset(get_sub_element(alert, "meta_attributes")), "recipient_list": get_all_recipients(alert) }) return alert_list
def get_all_recipients(alert): """ Returns list of all recipient of specified alert. Format: [ { "id": <id of recipient>, "value": <value of recipient>, "description": <recipient description>, "instance_attributes": <list of nvpairs>, "meta_attributes": <list of nvpairs> } ] alert -- parent element of recipients to return """ recipient_list = [] for recipient in alert.findall("./recipient"): recipient_list.append({ "id": recipient.get("id"), "value": recipient.get("value"), "description": recipient.get("description", ""), "instance_attributes": get_nvset(get_sub_element(recipient, "instance_attributes")), "meta_attributes": get_nvset(get_sub_element(recipient, "meta_attributes")) }) return recipient_list
def test_new_last(self): lib.get_sub_element(self.root, "new_element", "new_id", None) assert_xml_equal( """ <root> <sub_element/> <new_element id="new_id"/> </root> """, etree.tostring(self.root).decode())
def test_new_last(self): lib.get_sub_element(self.root, "new_element", "new_id", None) assert_xml_equal( """ <root> <sub_element/> <new_element id="new_id"/> </root> """, etree.tostring(self.root).decode() )
def arrange_first_nvset(tag_name, context_element, nvpair_dict): """ Arrange to context_element contains some nvset (with tag_name) with nvpairs corresponing to nvpair_dict. WARNING: does not solve multiple nvset (with tag_name) under context_element! Consider carefully if this is your case. Probably not. There could be more than one nvset. This function is DEPRECATED. Try to use update_nvset etc. This method updates nvset specified by tag_name. If specified nvset doesn't exist it will be created. Returns updated nvset element or None if nvpair_dict is empty. tag_name -- tag name of nvset element context_element -- parent element of nvset nvpair_dict -- dictionary of nvpairs """ if not nvpair_dict: return nvset_element = get_sub_element( context_element, tag_name, create_subelement_id(context_element, tag_name), new_index=0 ) update_nvset(nvset_element, nvpair_dict)
def arrange_first_nvset(tag_name, context_element, attribute_dict): """ Arrange to context_element contains some nvset (with tag_name) with nvpairs corresponing to attribute_dict. WARNING: does not solve multiple nvset (with tag_name) under context_element! Consider carefully if this is your case. Probably not. There could be more than one nvset. This function is DEPRECATED. Try to use update_nvset etc. This method updates nvset specified by tag_name. If specified nvset doesn't exist it will be created. Returns updated nvset element or None if attribute_dict is empty. tag_name -- tag name of nvset element context_element -- parent element of nvset attribute_dict -- dictionary of nvpairs """ if not attribute_dict: return nvset_element = get_sub_element( context_element, tag_name, create_subelement_id(context_element, tag_name), new_index=0 ) update_nvset(nvset_element, attribute_dict)
def test_new_no_id(self): assert_xml_equal( '<new_element/>', etree.tostring(lib.get_sub_element(self.root, "new_element")).decode()) assert_xml_equal( """ <root> <sub_element/> <new_element/> </root> """, etree.tostring(self.root).decode())
def test_new_with_id(self): assert_xml_equal( '<new_element id="new_id"/>', etree.tostring( lib.get_sub_element(self.root, "new_element", "new_id") ).decode() ) assert_xml_equal( """ <root> <sub_element/> <new_element id="new_id"/> </root> """, etree.tostring(self.root).decode() )
def test_sub_element_exists(self): self.assertEqual( self.sub, lib.get_sub_element(self.root, "sub_element") )
def test_sub_element_exists(self): self.assertEqual(self.sub, lib.get_sub_element(self.root, "sub_element"))