From 4b63891dd72163a1cd206263961924df1593baf4 Mon Sep 17 00:00:00 2001 From: Isaac Beckman Date: Thu, 13 Oct 2016 16:29:51 +0300 Subject: user's input should not be interpreted using python's "input" rather than "raw_input" raise exception since the user's input is interpreted. In python 3.x raw_input = input, so the interpertation bug only exists in python 2.x Change-Id: I28781a8742d6e03bc850fd0178f317474603a9d2 --- jenkins_jobs/utils.py | 1 + tests/cmd/subcommands/test_delete_all.py | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/jenkins_jobs/utils.py b/jenkins_jobs/utils.py index 4e28ad25..385f87ba 100644 --- a/jenkins_jobs/utils.py +++ b/jenkins_jobs/utils.py @@ -19,6 +19,7 @@ import codecs import fnmatch import locale import os.path +from six.moves import input def wrap_stream(stream, encoding='utf-8'): diff --git a/tests/cmd/subcommands/test_delete_all.py b/tests/cmd/subcommands/test_delete_all.py index 15fc23dd..39264994 100644 --- a/tests/cmd/subcommands/test_delete_all.py +++ b/tests/cmd/subcommands/test_delete_all.py @@ -17,8 +17,6 @@ # of actions by the JJB library, usually through interaction with the # python-jenkins library. -import six - from tests.base import mock from tests.cmd.test_cmd import CmdTestsBase @@ -27,8 +25,6 @@ from tests.cmd.test_cmd import CmdTestsBase mock.MagicMock) class DeleteAllTests(CmdTestsBase): - input_module = "jenkins_jobs.utils" if six.PY2 else "builtins" - @mock.patch('jenkins_jobs.cli.subcommand.update.' 'JenkinsManager.delete_all_jobs') def test_delete_all_accept(self, delete_job_mock): @@ -37,7 +33,7 @@ class DeleteAllTests(CmdTestsBase): """ args = ['--conf', self.default_config_file, 'delete-all'] - with mock.patch('%s.input' % self.input_module, return_value="y"): + with mock.patch('jenkins_jobs.utils.input', return_value="y"): self.execute_jenkins_jobs_with_args(args) @mock.patch('jenkins_jobs.cli.subcommand.update.' @@ -48,6 +44,6 @@ class DeleteAllTests(CmdTestsBase): """ args = ['--conf', self.default_config_file, 'delete-all'] - with mock.patch('%s.input' % self.input_module, return_value="n"): + with mock.patch('jenkins_jobs.utils.input', return_value="n"): self.assertRaises(SystemExit, self.execute_jenkins_jobs_with_args, args) -- cgit