mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 16:54:56 +02:00
[Apache v2] Implement delete_child() (#7521)
* Implement delete_child * Fix linter
This commit is contained in:
committed by
ohemorange
parent
d14eec9ecf
commit
517ff5cb19
@@ -300,9 +300,18 @@ class AugeasBlockNode(AugeasDirectiveNode):
|
||||
|
||||
return nodes
|
||||
|
||||
def delete_child(self, child): # pragma: no cover
|
||||
"""Deletes a ParserNode from the sequence of children"""
|
||||
pass
|
||||
def delete_child(self, child):
|
||||
"""
|
||||
Deletes a ParserNode from the sequence of children, and raises an
|
||||
exception if it's unable to do so.
|
||||
:param AugeasParserNode: child: A node to delete.
|
||||
"""
|
||||
if not self.parser.aug.remove(child.metadata["augeaspath"]):
|
||||
|
||||
raise errors.PluginError(
|
||||
("Could not delete child node, the Augeas path: {} doesn't " +
|
||||
"seem to exist.").format(child.metadata["augeaspath"])
|
||||
)
|
||||
|
||||
def unsaved_files(self):
|
||||
"""Returns a list of unsaved filepaths"""
|
||||
|
||||
@@ -144,6 +144,24 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
|
||||
found = True
|
||||
self.assertTrue(found)
|
||||
|
||||
def test_delete_child(self):
|
||||
listens = self.config.parser_root.find_directives("Listen")
|
||||
self.assertEqual(len(listens), 1)
|
||||
self.config.parser_root.primary.delete_child(listens[0])
|
||||
|
||||
listens = self.config.parser_root.find_directives("Listen")
|
||||
self.assertEqual(len(listens), 0)
|
||||
|
||||
def test_delete_child_not_found(self):
|
||||
listen = self.config.parser_root.find_directives("Listen")[0]
|
||||
listen.primary.metadata["augeaspath"] = "/files/something/nonexistent"
|
||||
|
||||
self.assertRaises(
|
||||
errors.PluginError,
|
||||
self.config.parser_root.delete_child,
|
||||
listen
|
||||
)
|
||||
|
||||
def test_add_child_block(self):
|
||||
nb = self.config.parser_root.primary.add_child_block(
|
||||
"NewBlock",
|
||||
|
||||
Reference in New Issue
Block a user