def test_set_attribute_adds_attribute(self):
     xsd_string = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><root><test></test></root></xs:schema>"
     xpath = "root/test"
     attribute_name = "attr"
     updated_xsd_string = set_attribute(xsd_string, xpath, attribute_name,
                                        "")
     self.assertTrue('<test attr=' in updated_xsd_string)
 def test_set_attribute_if_present(self):
     xsd_string = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" \
                  "<root><test attr='old'></test></root></xs:schema>"
     xpath = "root/test"
     attribute_name = "attr"
     attribute_value = "new"
     updated_xsd_string = set_attribute(xsd_string, xpath, attribute_name, attribute_value)
     self.assertTrue('<test attr="new"' in updated_xsd_string)
 def test_set_attribute_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):
         set_attribute(xsd_string, xpath, "", "")
 def test_set_attribute_invalid_xsd_raises_xsd_error(self):
     xsd_string = "invalid"
     with self.assertRaises(etree.XMLSyntaxError):
         set_attribute(xsd_string, "", "", "")