def _run_task(self): # Check that path exists if not os.path.isdir(self.options["path"]): raise TaskOptionsError( "The path {} does not exist or is not a directory".format( self.options["path"])) # Check that revert_path does not exist if os.path.exists(self.options["revert_path"]): raise TaskOptionsError( "The revert_path {} already exists. Delete it and try again". format(self.options["revert_path"])) # Copy path to revert_path copy_tree(self.options["path"], self.options["revert_path"]) # Edit metadata in path self.logger.info( "Preparing metadata in {0} for unmanaged EE deployment".format( self.options["path"])) for element in self.elements: fname_match, element_name = element.split(":") remove_xml_element_directory(element_name, os.path.join(self.options["path"]), fname_match) self.logger.info( "Metadata in {} is now prepared for unmanaged EE deployment". format(self.options["path"]))
def test_remove_xml_element_directory(self): with utils.temporary_dir() as d: path = os.path.join(d, "test.xml") with open(path, "w") as f: f.write( '<?xml version="1.0" ?>' '<root xmlns="http://soap.sforce.com/2006/04/metadata">' "<tag>text</tag></root>") utils.remove_xml_element_directory("tag", d, "*") with open(path, "r") as f: result = f.read() expected = """<?xml version='1.0' encoding='UTF-8'?> <root xmlns="http://soap.sforce.com/2006/04/metadata" />""" assert expected == result
def test_remove_xml_element_parse_error(self, mock_parse): err = ET.ParseError() err.msg = "it broke" err.lineno = 1 mock_parse.side_effect = err with utils.temporary_dir() as d: path = os.path.join(d, "test.xml") with open(path, "w") as f: f.write( '<?xml version="1.0" ?>' '<root xmlns="http://soap.sforce.com/2006/04/metadata">' "<tag>text</tag></root>") try: utils.remove_xml_element_directory("tag", d, "*") except ET.ParseError as err: assert str(err) == "it broke (test.xml, line 1)" else: assert False # Expected ParseError