summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-12-05 10:18:41 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-12-05 10:18:41 -0500
commita15439cbfd0cdc9687e80216ec43ae941d4b5323 (patch)
tree66c03faf8dfd35cd483cb2df3762d1e1a165ee30 /testsuite
parentabb1c51462d35b501bbf33bc8e91352208df1c8d (diff)
downloadbcfg2-a15439cbfd0cdc9687e80216ec43ae941d4b5323.tar.gz
bcfg2-a15439cbfd0cdc9687e80216ec43ae941d4b5323.tar.bz2
bcfg2-a15439cbfd0cdc9687e80216ec43ae941d4b5323.zip
testsuite: fixed Augeas unit tests in travis-ci
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py368
-rwxr-xr-xtestsuite/before_install.sh2
2 files changed, 185 insertions, 185 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
index bfcb8a378..8dbf51a1c 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIX/TestAugeas.py
@@ -47,187 +47,187 @@ test_data = """<Test>
test_xdata = lxml.etree.XML(test_data)
-class TestPOSIXAugeas(TestPOSIXTool):
- test_obj = POSIXAugeas
-
- applied_commands = dict(
- insert=lxml.etree.Element(
- "Insert", label="Thing",
- path='Test/Children[#attribute/identical = "true"]/Thing'),
- set=lxml.etree.Element("Set", path="Test/Text/#text",
- value="content with spaces"),
- move=lxml.etree.Element(
- "Move", source="Test/Foo",
- destination='Test/Children[#attribute/identical = "false"]/Foo'),
- remove=lxml.etree.Element("Remove", path="Test/Bar"),
- clear=lxml.etree.Element("Clear", path="Test/Empty/#text"),
- setm=lxml.etree.Element(
- "SetMulti", sub="#text", value="same",
- base='Test/Children[#attribute/multi = "true"]/Thing'))
-
-
- @skipUnless(HAS_AUGEAS, "Python Augeas libraries not found")
- def setUp(self):
- fd, self.tmpfile = tempfile.mkstemp()
- os.fdopen(fd, 'w').write(test_data)
-
- def tearDown(self):
- tmpfile = getattr(self, "tmpfile", None)
- if tmpfile:
- os.unlink(tmpfile)
-
- def test_fully_specified(self):
- ptool = self.get_obj()
-
- entry = lxml.etree.Element("Path", name="/test", type="augeas")
- self.assertFalse(ptool.fully_specified(entry))
-
- entry.text = "text"
- self.assertTrue(ptool.fully_specified(entry))
-
- def test_install(self):
- # this is tested adequately by the other tests
- pass
-
- def test_verify(self):
- # this is tested adequately by the other tests
- pass
-
- @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.verify")
- def _verify(self, commands, mock_verify):
- ptool = self.get_obj()
- mock_verify.return_value = True
-
- entry = lxml.etree.Element("Path", name=self.tmpfile, type="augeas",
- lens="Xml")
- entry.extend(commands)
-
- modlist = []
- self.assertTrue(ptool.verify(entry, modlist))
- mock_verify.assert_called_with(ptool, entry, modlist)
- self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
- test_xdata)
-
- def test_verify_insert(self):
- """ Test successfully verifying an Insert command """
- self._verify([self.applied_commands['insert']])
-
- def test_verify_set(self):
- """ Test successfully verifying a Set command """
- self._verify([self.applied_commands['set']])
-
- def test_verify_move(self):
- """ Test successfully verifying a Move command """
- self._verify([self.applied_commands['move']])
-
- def test_verify_remove(self):
- """ Test successfully verifying a Remove command """
- self._verify([self.applied_commands['remove']])
-
- def test_verify_clear(self):
- """ Test successfully verifying a Clear command """
- self._verify([self.applied_commands['clear']])
-
- def test_verify_set_multi(self):
- """ Test successfully verifying a SetMulti command """
- self._verify([self.applied_commands['setm']])
-
- def test_verify_all(self):
- """ Test successfully verifying multiple commands """
- self._verify(self.applied_commands.values())
-
- @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.install")
- def _install(self, commands, expected, mock_install):
- ptool = self.get_obj()
- mock_install.return_value = True
-
- entry = lxml.etree.Element("Path", name=self.tmpfile, type="augeas",
- lens="Xml")
- entry.extend(commands)
-
- self.assertTrue(ptool.install(entry))
- mock_install.assert_called_with(ptool, entry)
- self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
- expected)
-
- def test_install_set_existing(self):
- """ Test setting the value of an existing node """
- expected = copy.deepcopy(test_xdata)
- expected.find("Text").text = "Changed content"
- self._install([lxml.etree.Element("Set", path="Test/Text/#text",
- value="Changed content")],
- expected)
-
- def test_install_set_new(self):
- """ Test setting the value of an new node """
- expected = copy.deepcopy(test_xdata)
- newtext = lxml.etree.SubElement(expected, "NewText")
- newtext.text = "new content"
- self._install([lxml.etree.Element("Set", path="Test/NewText/#text",
- value="new content")],
- expected)
-
- def test_install_remove(self):
- """ Test removing a node """
- expected = copy.deepcopy(test_xdata)
- expected.remove(expected.find("Attrs"))
- self._install(
- [lxml.etree.Element("Remove",
- path='Test/*[#attribute/foo = "foo"]')],
- expected)
-
- def test_install_move(self):
- """ Test moving a node """
- expected = copy.deepcopy(test_xdata)
- foo = expected.xpath("//Foo")[0]
- expected.append(foo)
- self._install(
- [lxml.etree.Element("Move", source='Test/Children/Foo',
- destination='Test/Foo')],
- expected)
-
- def test_install_clear(self):
- """ Test clearing a node """
- # TODO: clearing a node doesn't seem to work with the XML lens
- #
- # % augtool -b
- # augtool> set /augeas/load/Xml/incl[3] "/tmp/test.xml"
- # augtool> load
- # augtool> clear '/files/tmp/test.xml/Test/Text/#text'
- # augtool> save
- # error: Failed to execute command
- # saving failed (run 'print /augeas//error' for details)
- # augtool> print /augeas//error
- #
- # The error isn't useful.
- pass
-
- def test_install_set_multi(self):
- """ Test setting multiple nodes at once """
- expected = copy.deepcopy(test_xdata)
- for thing in expected.xpath("Children[@identical='true']/Thing"):
- thing.text = "same"
- self._install(
- [lxml.etree.Element(
- "SetMulti", value="same",
- base='Test/Children[#attribute/identical = "true"]',
- sub="Thing/#text")],
- expected)
-
- def test_install_insert(self):
- """ Test inserting a node """
- expected = copy.deepcopy(test_xdata)
- children = expected.xpath("Children[@identical='true']")[0]
- thing = lxml.etree.Element("Thing")
- thing.text = "three"
- children.append(thing)
- self._install(
- [lxml.etree.Element(
- "Insert",
- path='Test/Children[#attribute/identical = "true"]/Thing[2]',
- label="Thing", where="after"),
- lxml.etree.Element(
- "Set",
- path='Test/Children[#attribute/identical = "true"]/Thing[3]/#text',
- value="three")],
- expected)
+if can_skip or HAS_AUGEAS:
+ class TestPOSIXAugeas(TestPOSIXTool):
+ test_obj = POSIXAugeas
+
+ applied_commands = dict(
+ insert=lxml.etree.Element(
+ "Insert", label="Thing",
+ path='Test/Children[#attribute/identical = "true"]/Thing'),
+ set=lxml.etree.Element("Set", path="Test/Text/#text",
+ value="content with spaces"),
+ move=lxml.etree.Element(
+ "Move", source="Test/Foo",
+ destination='Test/Children[#attribute/identical = "false"]/Foo'),
+ remove=lxml.etree.Element("Remove", path="Test/Bar"),
+ clear=lxml.etree.Element("Clear", path="Test/Empty/#text"),
+ setm=lxml.etree.Element(
+ "SetMulti", sub="#text", value="same",
+ base='Test/Children[#attribute/multi = "true"]/Thing'))
+
+ @skipUnless(HAS_AUGEAS, "Python Augeas libraries not found")
+ def setUp(self):
+ fd, self.tmpfile = tempfile.mkstemp()
+ os.fdopen(fd, 'w').write(test_data)
+
+ def tearDown(self):
+ tmpfile = getattr(self, "tmpfile", None)
+ if tmpfile:
+ os.unlink(tmpfile)
+
+ def test_fully_specified(self):
+ ptool = self.get_obj()
+
+ entry = lxml.etree.Element("Path", name="/test", type="augeas")
+ self.assertFalse(ptool.fully_specified(entry))
+
+ entry.text = "text"
+ self.assertTrue(ptool.fully_specified(entry))
+
+ def test_install(self):
+ # this is tested adequately by the other tests
+ pass
+
+ def test_verify(self):
+ # this is tested adequately by the other tests
+ pass
+
+ @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.verify")
+ def _verify(self, commands, mock_verify):
+ ptool = self.get_obj()
+ mock_verify.return_value = True
+
+ entry = lxml.etree.Element("Path", name=self.tmpfile,
+ type="augeas", lens="Xml")
+ entry.extend(commands)
+
+ modlist = []
+ self.assertTrue(ptool.verify(entry, modlist))
+ mock_verify.assert_called_with(ptool, entry, modlist)
+ self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
+ test_xdata)
+
+ def test_verify_insert(self):
+ """ Test successfully verifying an Insert command """
+ self._verify([self.applied_commands['insert']])
+
+ def test_verify_set(self):
+ """ Test successfully verifying a Set command """
+ self._verify([self.applied_commands['set']])
+
+ def test_verify_move(self):
+ """ Test successfully verifying a Move command """
+ self._verify([self.applied_commands['move']])
+
+ def test_verify_remove(self):
+ """ Test successfully verifying a Remove command """
+ self._verify([self.applied_commands['remove']])
+
+ def test_verify_clear(self):
+ """ Test successfully verifying a Clear command """
+ self._verify([self.applied_commands['clear']])
+
+ def test_verify_set_multi(self):
+ """ Test successfully verifying a SetMulti command """
+ self._verify([self.applied_commands['setm']])
+
+ def test_verify_all(self):
+ """ Test successfully verifying multiple commands """
+ self._verify(self.applied_commands.values())
+
+ @patch("Bcfg2.Client.Tools.POSIX.Augeas.POSIXTool.install")
+ def _install(self, commands, expected, mock_install):
+ ptool = self.get_obj()
+ mock_install.return_value = True
+
+ entry = lxml.etree.Element("Path", name=self.tmpfile,
+ type="augeas", lens="Xml")
+ entry.extend(commands)
+
+ self.assertTrue(ptool.install(entry))
+ mock_install.assert_called_with(ptool, entry)
+ self.assertXMLEqual(lxml.etree.parse(self.tmpfile).getroot(),
+ expected)
+
+ def test_install_set_existing(self):
+ """ Test setting the value of an existing node """
+ expected = copy.deepcopy(test_xdata)
+ expected.find("Text").text = "Changed content"
+ self._install([lxml.etree.Element("Set", path="Test/Text/#text",
+ value="Changed content")],
+ expected)
+
+ def test_install_set_new(self):
+ """ Test setting the value of an new node """
+ expected = copy.deepcopy(test_xdata)
+ newtext = lxml.etree.SubElement(expected, "NewText")
+ newtext.text = "new content"
+ self._install([lxml.etree.Element("Set", path="Test/NewText/#text",
+ value="new content")],
+ expected)
+
+ def test_install_remove(self):
+ """ Test removing a node """
+ expected = copy.deepcopy(test_xdata)
+ expected.remove(expected.find("Attrs"))
+ self._install(
+ [lxml.etree.Element("Remove",
+ path='Test/*[#attribute/foo = "foo"]')],
+ expected)
+
+ def test_install_move(self):
+ """ Test moving a node """
+ expected = copy.deepcopy(test_xdata)
+ foo = expected.xpath("//Foo")[0]
+ expected.append(foo)
+ self._install(
+ [lxml.etree.Element("Move", source='Test/Children/Foo',
+ destination='Test/Foo')],
+ expected)
+
+ def test_install_clear(self):
+ """ Test clearing a node """
+ # TODO: clearing a node doesn't seem to work with the XML lens
+ #
+ # % augtool -b
+ # augtool> set /augeas/load/Xml/incl[3] "/tmp/test.xml"
+ # augtool> load
+ # augtool> clear '/files/tmp/test.xml/Test/Text/#text'
+ # augtool> save
+ # error: Failed to execute command
+ # saving failed (run 'print /augeas//error' for details)
+ # augtool> print /augeas//error
+ #
+ # The error isn't useful.
+ pass
+
+ def test_install_set_multi(self):
+ """ Test setting multiple nodes at once """
+ expected = copy.deepcopy(test_xdata)
+ for thing in expected.xpath("Children[@identical='true']/Thing"):
+ thing.text = "same"
+ self._install(
+ [lxml.etree.Element(
+ "SetMulti", value="same",
+ base='Test/Children[#attribute/identical = "true"]',
+ sub="Thing/#text")],
+ expected)
+
+ def test_install_insert(self):
+ """ Test inserting a node """
+ expected = copy.deepcopy(test_xdata)
+ children = expected.xpath("Children[@identical='true']")[0]
+ thing = lxml.etree.Element("Thing")
+ thing.text = "three"
+ children.append(thing)
+ self._install(
+ [lxml.etree.Element(
+ "Insert",
+ path='Test/Children[#attribute/identical = "true"]/Thing[2]',
+ label="Thing", where="after"),
+ lxml.etree.Element(
+ "Set",
+ path='Test/Children[#attribute/identical = "true"]/Thing[3]/#text',
+ value="three")],
+ expected)
diff --git a/testsuite/before_install.sh b/testsuite/before_install.sh
index 5f1a59aaf..1c781a218 100755
--- a/testsuite/before_install.sh
+++ b/testsuite/before_install.sh
@@ -8,6 +8,6 @@ sudo apt-get update -qq
sudo apt-get install -qq swig libxml2-utils
if [[ "$WITH_OPTIONAL_DEPS" == "yes" ]]; then
if [[ ${PYVER:0:1} == "2" ]]; then
- sudo apt-get install -qq python-selinux python-pylibacl yum
+ sudo apt-get install -qq python-selinux python-pylibacl yum python-augeas
fi
fi