def test_delete_appinfo_element_element_absent_from_two_appinfo_does_not_fail( 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" delete_appinfo_element(xsd_string, xpath, "attribute")
def test_delete_attribute_does_not_fail_if_not_present(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" attribute_name = "attribute" delete_appinfo_element(xsd_string, xpath, attribute_name)
def test_delete_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): delete_appinfo_element(xsd_string, xpath, "")
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): delete_appinfo_element(xsd_string, xpath, "attribute")
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 = delete_appinfo_element(xsd_string, xpath, "attribute") expected_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> """ 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_delete_appinfo_element_removed_if_exists(self): xsd_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> """ xpath = "xs:element" attribute_name = "attribute" updated_xsd_string = delete_appinfo_element(xsd_string, xpath, attribute_name) expected_string = """ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:annotation><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_delete_appinfo_element_removed_if_exists(self): xsd_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>' xpath = "xs:element" attribute_name = "attribute" updated_xsd_string = delete_appinfo_element(xsd_string, xpath, attribute_name) expected_string = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="root">' \ '<xs:annotation><xs:appinfo/></xs:annotation>' \ '</xs:element></xs:schema>' self.assertEquals(updated_xsd_string, expected_string)
def delete_module(template, xpath): """Deletes a module from a template Args: template: xpath: Returns: """ # delete module attribute from element template.content = delete_appinfo_element(template.content, xpath, MODULE_TAG_NAME) return template_api.upsert(template)
def test_add_appinfo_element_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 = delete_appinfo_element(xsd_string, xpath, "attribute") expected_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>' self.assertEquals(updated_xsd_string, expected_string)
def test_delete_appinfo_element_invalid_xsd_raises_xsd_error(self): xsd_string = "invalid" with self.assertRaises(etree.XMLSyntaxError): delete_appinfo_element(xsd_string, "", "")