def test_add_appinfo_element_invalid_xpath_raises_xsd_error(self): xsd_string = """ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <root><test></test></root> </xs:schema> """ xpath = "invalid" with self.assertRaises(XMLError): add_appinfo_element(xsd_string, xpath, "attribute", "value")
def test_add_appinfo_element_element_present_in_two_appinfo_raises_exception( self): xsd_string = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element name='root'><xs:annotation>" \ "<xs:appinfo><attribute>old</attribute></xs:appinfo>" \ "<xs:appinfo><attribute>old</attribute></xs:appinfo></xs:annotation></xs:element></xs:schema>" xpath = "xs:element" with self.assertRaises(XMLError): add_appinfo_element(xsd_string, xpath, "attribute", "new")
def test_add_appinfo_element_no_element_adds_it(self): xsd_string = """ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"><xs:annotation> <xs:appinfo></xs:appinfo></xs:annotation></xs:element> </xs:schema> """ xpath = "xs:element" updated_xsd_string = add_appinfo_element(xsd_string, xpath, "attribute", "value") expected_string = """ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:annotation> <xs:appinfo><attribute>value</attribute></xs:appinfo> </xs:annotation> </xs:element> </xs:schema> """ updated_tree = XSDTree.fromstring(updated_xsd_string) updated_xsd_string = XSDTree.tostring(updated_tree) expected_tree = XSDTree.fromstring(expected_string) expected_string = XSDTree.tostring(expected_tree) self.assertEqual(updated_xsd_string, expected_string)
def test_add_appinfo_element_present_in_second_of_two_appinfo(self): xsd_string = """ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:annotation> <xs:appinfo></xs:appinfo> <xs:appinfo><attribute>old</attribute></xs:appinfo> </xs:annotation> </xs:element> </xs:schema> """ xpath = "xs:element" updated_xsd_string = add_appinfo_element(xsd_string, xpath, "attribute", "new") expected_string = """ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:annotation> <xs:appinfo/> <xs:appinfo><attribute>new</attribute></xs:appinfo> </xs:annotation> </xs:element> </xs:schema> """ updated_tree = XSDTree.fromstring(updated_xsd_string) updated_xsd_string = XSDTree.tostring(updated_tree) expected_tree = XSDTree.fromstring(expected_string) expected_string = XSDTree.tostring(expected_tree) self.assertEqual(updated_xsd_string, expected_string)
def test_add_appinfo_element_no_annotation_adds_it(self): xsd_string = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element name='root'/></xs:schema>" xpath = "xs:element" updated_xsd_string = add_appinfo_element(xsd_string, xpath, "attribute", "value") expected_string = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="root">' \ '<xs:annotation><xs:appinfo><attribute>value</attribute></xs:appinfo></xs:annotation>' \ '</xs:element></xs:schema>' self.assertEquals(updated_xsd_string, expected_string)
def test_add_appinfo_element_element_absent_from_two_appinfo(self): xsd_string = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element name='root'><xs:annotation>" \ "<xs:appinfo></xs:appinfo><xs:appinfo></xs:appinfo></xs:annotation></xs:element></xs:schema>" xpath = "xs:element" updated_xsd_string = add_appinfo_element(xsd_string, xpath, "attribute", "new") expected_string = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="root">' \ '<xs:annotation><xs:appinfo><attribute>new</attribute></xs:appinfo><xs:appinfo/>' \ '</xs:annotation></xs:element></xs:schema>' self.assertEquals(updated_xsd_string, expected_string)
def add_module(template, module_id, xpath): """Inserts a module in a template Args: template: module_id: xpath: Returns: """ # get the module module_object = get_by_id(module_id) template.content = add_appinfo_element(template.content, xpath, MODULE_TAG_NAME, module_object.url) return template_api.upsert(template)
def test_add_appinfo_element_invalid_xsd_raises_xsd_error(self): xsd_string = "invalid" with self.assertRaises(etree.XMLSyntaxError): add_appinfo_element(xsd_string, "", "", "")