def test_run_non_root(self, mock_setup, mock_parse, mock_is_root, mock_log_fatal, mock_exit): mock_is_root.return_value = False ctx = mock.Mock(process_name="preflight_check") mock_exit.side_effect = SystemExit with self.assertRaises(SystemExit): main.run(ctx) mock_setup.assert_called_once_with(ctx) mock_parse.assert_called_once_with(ctx) mock_is_root.assert_called_once_with() mock_log_fatal.assert_called_once_with("{} can only be executed as user root!".format(ctx.process_name)) mock_exit.assert_called_once_with(1)
def test_run(self, mock_setup, mock_parse, mock_is_root, mock_exists, mock_mkdir, mock_setup_logging, mock_fix, mock_check, mock_kill, mock_fence, mock_sb): mock_is_root.return_value = True ctx = mock.Mock(var_dir="/var/lib/preflight_check") mock_exists.return_value = False main.run(ctx) mock_setup.assert_called_once_with(ctx) mock_parse.assert_called_once_with(ctx) mock_is_root.assert_called_once_with() mock_exists.assert_called_once_with(ctx.var_dir) mock_mkdir.assert_called_once_with(ctx.var_dir, exist_ok=True) mock_setup_logging.assert_called_once_with(ctx) mock_check.assert_called_once_with(ctx) mock_fix.assert_called_once_with(ctx) mock_kill.assert_called_once_with(ctx) mock_fence.assert_called_once_with(ctx) mock_sb.assert_called_once_with(ctx)
def test_run_except(self, mock_setup, mock_parse, mock_is_root, mock_exists, mock_setup_logging, mock_fix, mock_check, mock_dumps, mock_exit): mock_is_root.return_value = True ctx = mock.Mock(var_dir="/var/lib/preflight_check") mock_exists.return_value = True mock_check.side_effect = KeyboardInterrupt mock_exit.side_effect = SystemExit with self.assertRaises(SystemExit): main.run(ctx) mock_setup.assert_called_once_with(ctx) mock_parse.assert_called_once_with(ctx) mock_is_root.assert_called_once_with() mock_exists.assert_called_once_with(ctx.var_dir) mock_setup_logging.assert_called_once_with(ctx) mock_check.assert_called_once_with(ctx) mock_fix.assert_called_once_with(ctx) mock_dumps.assert_called_once_with() mock_exit.assert_called_once_with(1)