summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-12 16:02:24 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-02-14 14:57:04 -0500
commit43984bc5ebc59bd8c5890ed6ba3de162e6698dcc (patch)
treed9e972b160d5d5033537495e9f507cfe043483c3 /testsuite
parentd526c8745b61c1977b775cfe750a86c51dd6a9f3 (diff)
downloadbcfg2-43984bc5ebc59bd8c5890ed6ba3de162e6698dcc.tar.gz
bcfg2-43984bc5ebc59bd8c5890ed6ba3de162e6698dcc.tar.bz2
bcfg2-43984bc5ebc59bd8c5890ed6ba3de162e6698dcc.zip
better Executor class for client tools
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py84
-rw-r--r--testsuite/Testsrc/test_code_checks.py6
2 files changed, 10 insertions, 80 deletions
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
index 8ab279a50..582f0ac99 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/TestPOSIXUsers.py
@@ -20,78 +20,6 @@ while path != "/":
from common import *
-class TestExecutor(Bcfg2TestCase):
- test_obj = Executor
-
- def get_obj(self, logger=None):
- if not logger:
- def print_msg(msg):
- print(msg)
- logger = Mock()
- logger.error = Mock(side_effect=print_msg)
- logger.warning = Mock(side_effect=print_msg)
- logger.info = Mock(side_effect=print_msg)
- logger.debug = Mock(side_effect=print_msg)
- return self.test_obj(logger)
-
- @patch("subprocess.Popen")
- def test_run(self, mock_Popen):
- exc = self.get_obj()
- cmd = ["/bin/test", "-a", "foo"]
- proc = Mock()
- proc.wait = Mock()
- proc.wait.return_value = 0
- proc.communicate = Mock()
- proc.communicate.return_value = (MagicMock(), MagicMock())
- mock_Popen.return_value = proc
-
- self.assertTrue(exc.run(cmd))
- args = mock_Popen.call_args
- self.assertEqual(args[0][0], cmd)
- self.assertEqual(args[1]['shell'], False)
- self.assertEqual(args[1]['stdin'], subprocess.PIPE)
- self.assertEqual(args[1]['stdout'], subprocess.PIPE)
- self.assertEqual(args[1]['stderr'], subprocess.PIPE)
- proc.communicate.assert_called_with()
- proc.wait.assert_called_with()
- self.assertEqual(proc.communicate.return_value,
- (exc.stdout, exc.stderr))
- self.assertEqual(proc.wait.return_value,
- exc.retval)
-
- mock_Popen.reset_mock()
- inputdata = "foo\n\nbar"
- self.assertTrue(exc.run(cmd, inputdata=inputdata, shell=True))
- args = mock_Popen.call_args
- self.assertEqual(args[0][0], cmd)
- self.assertEqual(args[1]['shell'], True)
- self.assertEqual(args[1]['stdin'], subprocess.PIPE)
- self.assertEqual(args[1]['stdout'], subprocess.PIPE)
- self.assertEqual(args[1]['stderr'], subprocess.PIPE)
- proc.communicate.assert_called_with(inputdata)
- proc.wait.assert_called_with()
- self.assertEqual(proc.communicate.return_value,
- (exc.stdout, exc.stderr))
- self.assertEqual(proc.wait.return_value,
- exc.retval)
-
- mock_Popen.reset_mock()
- proc.wait.return_value = 1
- self.assertRaises(ExecutionError, exc.run, cmd)
- args = mock_Popen.call_args
- self.assertEqual(args[0][0], cmd)
- self.assertEqual(args[1]['shell'], False)
- self.assertEqual(args[1]['stdin'], subprocess.PIPE)
- self.assertEqual(args[1]['stdout'], subprocess.PIPE)
- self.assertEqual(args[1]['stderr'], subprocess.PIPE)
- proc.communicate.assert_called_with()
- proc.wait.assert_called_with()
- self.assertEqual(proc.communicate.return_value,
- (exc.stdout, exc.stderr))
- self.assertEqual(proc.wait.return_value,
- exc.retval)
-
-
class TestPOSIXUsers(Bcfg2TestCase):
test_obj = POSIXUsers
@@ -419,6 +347,10 @@ class TestPOSIXUsers(Bcfg2TestCase):
setter.reset_mock()
users.modified = []
+ cmd_rv = Mock()
+ cmd_rv.success = True
+ users.cmd.run.return_value = cmd_rv
+
reset()
entry = lxml.etree.Element("POSIXUser", name="test2")
self.assertTrue(users._install(entry))
@@ -438,7 +370,7 @@ class TestPOSIXUsers(Bcfg2TestCase):
self.assertIn(entry, users.modified)
reset()
- users.cmd.run.side_effect = ExecutionError(None)
+ cmd_rv.success = False
self.assertFalse(users._install(entry))
users.set_defaults[entry.tag].assert_called_with(entry)
users._get_cmd.assert_called_with("mod",
@@ -536,19 +468,21 @@ class TestPOSIXUsers(Bcfg2TestCase):
users = self.get_obj()
users._get_cmd = Mock()
users.cmd = Mock()
+ cmd_rv = Mock()
+ cmd_rv.success = True
+ users.cmd.run.return_value = cmd_rv
def reset():
users._get_cmd.reset_mock()
users.cmd.reset_mock()
-
entry = lxml.etree.Element("POSIXUser", name="test2")
self.assertTrue(users._remove(entry))
users._get_cmd.assert_called_with("del", entry)
users.cmd.run.assert_called_with(users._get_cmd.return_value)
reset()
- users.cmd.run.side_effect = ExecutionError(None)
+ cmd_rv.success = False
self.assertFalse(users._remove(entry))
users._get_cmd.assert_called_with("del", entry)
users.cmd.run.assert_called_with(users._get_cmd.return_value)
diff --git a/testsuite/Testsrc/test_code_checks.py b/testsuite/Testsrc/test_code_checks.py
index ded9cd8e3..3404c19ce 100644
--- a/testsuite/Testsrc/test_code_checks.py
+++ b/testsuite/Testsrc/test_code_checks.py
@@ -62,13 +62,9 @@ error_checks = {
"lib/Bcfg2/Server": ["Reports", "SchemaUpdater"],
"lib/Bcfg2/Server/Admin": ["Compare.py",
"Snapshots.py"],
- "lib/Bcfg2/Client/Tools": ["launchd.py",
- "OpenCSW.py",
+ "lib/Bcfg2/Client/Tools": ["OpenCSW.py",
"Blast.py",
- "SYSV.py",
"FreeBSDInit.py",
- "DebInit.py",
- "RcUpdate.py",
"VCS.py",
"YUM24.py"],
"lib/Bcfg2/Server/Plugins": ["Deps.py",