def test_start_message(self, check_mock): check_mock.return_value = "test" mgmt_command = router.Command() output = mgmt_command.salmon_start() self.assertEqual( output, ["Starting Salmon handler: inboxen.router.config.boot\n"])
def test_process_error(self, check_mock): check_mock.side_effect = CalledProcessError(-1, "salmon", "test") mgmt_command = router.Command() output = mgmt_command.salmon_start() self.assertEqual(output, ["Exit code -1: test"]) output = mgmt_command.salmon_status() self.assertEqual(output, ["Exit code -1: test"]) output = mgmt_command.salmon_stop() self.assertEqual(output, ["Exit code -1: test"])
def test_handle(self): def func(): raise OSError mgmt_command = router.Command() with self.assertRaises(CommandError) as error: mgmt_command.handle(cmd=func) self.assertEqual(error.exception.message, "OSError from subprocess, salmon is probably not in your path.") mgmt_command.stdout = StringIO() mgmt_command.handle(cmd=lambda: "test") self.assertEqual(mgmt_command.stdout.getvalue(), "test")