Fix _run_hook test

This commit is contained in:
Peter Eckersley
2016-03-30 17:41:59 -07:00
parent 285f3b5536
commit 526aa7d5ae
+12 -11
View File
@@ -81,18 +81,19 @@ class HookTest(unittest.TestCase):
self._test_a_hook(config, rhook, 0) self._test_a_hook(config, rhook, 0)
self.assertEqual(mock_print.call_count, 2) self.assertEqual(mock_print.call_count, 2)
@mock.patch('letsencrypt.hooks.logger.error')
@mock.patch('letsencrypt.hooks.Popen') @mock.patch('letsencrypt.hooks.Popen')
def test_run_hook(self, mock_popen, mock_error): def test_run_hook(self, mock_popen):
mock_cmd = mock.MagicMock() with mock.patch('letsencrypt.hooks.logger.error') as mock_error:
mock_cmd.returncode = 1 mock_cmd = mock.MagicMock()
mock_cmd.communicate.return_value = ("", "") mock_cmd.returncode = 1
mock_popen.return_value = mock_cmd mock_cmd.communicate.return_value = ("", "")
hooks._run_hook("ls") mock_popen.return_value = mock_cmd
self.assertEqual(mock_error.call_count, 1) hooks._run_hook("ls")
mock_cmd.communicate.return_value = ("", "thing") self.assertEqual(mock_error.call_count, 1)
hooks._run_hook("ls") with mock.patch('letsencrypt.hooks.logger.error') as mock_error:
self.assertEqual(mock_error.call_count, 2) mock_cmd.communicate.return_value = ("", "thing")
hooks._run_hook("ls")
self.assertEqual(mock_error.call_count, 2)
if __name__ == '__main__': if __name__ == '__main__':