summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Rosmaita <rosmaita.fossdev@gmail.com>2018-03-29 17:21:59 -0400
committerCyril Roelandt <cyril@redhat.com>2018-04-06 17:09:11 +0200
commit22568b0c131e41d57b9c24631925517c933307bc (patch)
treee51b3ade6f6219c59fdfcc1e63315ce58d171893
parentba425b0b9287a2eff528bb5bc5b5a583ec280edc (diff)
downloadpython-glanceclient-22568b0c131e41d57b9c24631925517c933307bc.tar.gz
Fix intermittent v2 shell unit test failures
The do_image_download code has a check to make sure that there's a place to put the data (either filename or stdout redirect) before initiating the download. The location of this check was moved by change I841bebeda38814235079429eca0b1e5fd2f04dae to happen at the beginning of the function. The two intermittently failing tests do not explicitly address the check condition, and as a result the tests do exit early, but before they can check what they're supposed to be testing. Closes-bug: #1759951 Change-Id: I3c85bb358f669504b364d55618c21382b7a2a66b (cherry picked from commit dc3ee4aedbd9023bba1581a987b517f00b9bfd0e)
-rw-r--r--glanceclient/tests/unit/v2/test_shell_v2.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py
index c208f95..add91b7 100644
--- a/glanceclient/tests/unit/v2/test_shell_v2.py
+++ b/glanceclient/tests/unit/v2/test_shell_v2.py
@@ -758,10 +758,13 @@ class ShellV2Test(testtools.TestCase):
self.assert_exits_with_msg(func=test_shell.do_image_delete,
func_args=args)
+ @mock.patch('sys.stdout', autospec=True)
@mock.patch.object(utils, 'print_err')
- def test_do_image_download_with_forbidden_id(self, mocked_print_err):
+ def test_do_image_download_with_forbidden_id(self, mocked_print_err,
+ mocked_stdout):
args = self._make_args({'id': 'IMG-01', 'file': None,
'progress': False})
+ mocked_stdout.isatty = lambda: False
with mock.patch.object(self.gc.images, 'data') as mocked_data:
mocked_data.side_effect = exc.HTTPForbidden
try:
@@ -773,10 +776,12 @@ class ShellV2Test(testtools.TestCase):
self.assertEqual(1, mocked_data.call_count)
self.assertEqual(1, mocked_print_err.call_count)
+ @mock.patch('sys.stdout', autospec=True)
@mock.patch.object(utils, 'print_err')
- def test_do_image_download_with_500(self, mocked_print_err):
+ def test_do_image_download_with_500(self, mocked_print_err, mocked_stdout):
args = self._make_args({'id': 'IMG-01', 'file': None,
'progress': False})
+ mocked_stdout.isatty = lambda: False
with mock.patch.object(self.gc.images, 'data') as mocked_data:
mocked_data.side_effect = exc.HTTPInternalServerError
try: