Merge "Prevent test runs from cluttering current directory"

This commit is contained in:
Jenkins 2016-01-29 12:26:13 +00:00 committed by Gerrit Code Review
commit 6f431ee065

@ -336,15 +336,17 @@ class TestShell(testtools.TestCase):
with mock.patch(BUILTIN_OPEN) as mock_open: with mock.patch(BUILTIN_OPEN) as mock_open:
argv = ["", "download", "container"] argv = ["", "download", "container"]
swiftclient.shell.main(argv) swiftclient.shell.main(argv)
calls = [mock.call('container', 'object', calls = [mock.call('container', 'object',
headers={}, resp_chunk_size=65536, headers={}, resp_chunk_size=65536,
response_dict={}), response_dict={}),
mock.call('container', 'pseudo/', mock.call('container', 'pseudo/',
headers={}, resp_chunk_size=65536, headers={}, resp_chunk_size=65536,
response_dict={})] response_dict={})]
connection.return_value.get_object.assert_has_calls( connection.return_value.get_object.assert_has_calls(
calls, any_order=True) calls, any_order=True)
mock_open.assert_called_once_with('object', 'wb') mock_open.assert_called_once_with('object', 'wb')
self.assertEqual([mock.call('pseudo')], makedirs.mock_calls)
makedirs.reset_mock()
# Test downloading single object # Test downloading single object
objcontent = six.BytesIO(b'objcontent') objcontent = six.BytesIO(b'objcontent')
@ -356,10 +358,11 @@ class TestShell(testtools.TestCase):
with mock.patch(BUILTIN_OPEN) as mock_open: with mock.patch(BUILTIN_OPEN) as mock_open:
argv = ["", "download", "container", "object"] argv = ["", "download", "container", "object"]
swiftclient.shell.main(argv) swiftclient.shell.main(argv)
connection.return_value.get_object.assert_called_with( connection.return_value.get_object.assert_called_with(
'container', 'object', headers={}, resp_chunk_size=65536, 'container', 'object', headers={}, resp_chunk_size=65536,
response_dict={}) response_dict={})
mock_open.assert_called_with('object', 'wb') mock_open.assert_called_with('object', 'wb')
self.assertEqual([], makedirs.mock_calls)
# Test downloading single object to stdout # Test downloading single object to stdout
objcontent = six.BytesIO(b'objcontent') objcontent = six.BytesIO(b'objcontent')
@ -396,13 +399,18 @@ class TestShell(testtools.TestCase):
] ]
with mock.patch(BUILTIN_OPEN) as mock_open: with mock.patch(BUILTIN_OPEN) as mock_open:
argv = ["", "download", "--all"] with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
swiftclient.shell.main(argv) argv = ["", "download", "--all"]
self.assertEqual(3, mock_shuffle.call_count) swiftclient.shell.main(argv)
mock_shuffle.assert_any_call(['container']) self.assertEqual(3, mock_shuffle.call_count)
mock_shuffle.assert_any_call(['object']) mock_shuffle.assert_any_call(['container'])
mock_shuffle.assert_any_call(['pseudo/']) mock_shuffle.assert_any_call(['object'])
mock_open.assert_called_once_with('container/object', 'wb') mock_shuffle.assert_any_call(['pseudo/'])
mock_open.assert_called_once_with('container/object', 'wb')
self.assertEqual([
mock.call('container'),
mock.call('container/pseudo'),
], mock_mkdir.mock_calls)
# Test that the container and object lists are not shuffled # Test that the container and object lists are not shuffled
mock_shuffle.reset_mock() mock_shuffle.reset_mock()
@ -418,10 +426,15 @@ class TestShell(testtools.TestCase):
] ]
with mock.patch(BUILTIN_OPEN) as mock_open: with mock.patch(BUILTIN_OPEN) as mock_open:
argv = ["", "download", "--all", "--no-shuffle"] with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
swiftclient.shell.main(argv) argv = ["", "download", "--all", "--no-shuffle"]
self.assertEqual(0, mock_shuffle.call_count) swiftclient.shell.main(argv)
mock_open.assert_called_once_with('container/object', 'wb') self.assertEqual(0, mock_shuffle.call_count)
mock_open.assert_called_once_with('container/object', 'wb')
self.assertEqual([
mock.call('container'),
mock.call('container/pseudo'),
], mock_mkdir.mock_calls)
@mock.patch('swiftclient.service.Connection') @mock.patch('swiftclient.service.Connection')
def test_download_no_content_type(self, connection): def test_download_no_content_type(self, connection):
@ -439,17 +452,21 @@ class TestShell(testtools.TestCase):
connection.return_value.attempts = 0 connection.return_value.attempts = 0
with mock.patch(BUILTIN_OPEN) as mock_open: with mock.patch(BUILTIN_OPEN) as mock_open:
argv = ["", "download", "container"] with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
swiftclient.shell.main(argv) argv = ["", "download", "container"]
calls = [mock.call('container', 'object', swiftclient.shell.main(argv)
headers={}, resp_chunk_size=65536, calls = [mock.call('container', 'object',
response_dict={}), headers={}, resp_chunk_size=65536,
mock.call('container', 'pseudo/', response_dict={}),
headers={}, resp_chunk_size=65536, mock.call('container', 'pseudo/',
response_dict={})] headers={}, resp_chunk_size=65536,
connection.return_value.get_object.assert_has_calls( response_dict={})]
calls, any_order=True) connection.return_value.get_object.assert_has_calls(
mock_open.assert_called_once_with('object', 'wb') calls, any_order=True)
mock_open.assert_called_once_with('object', 'wb')
self.assertEqual([
mock.call('pseudo'),
], mock_mkdir.mock_calls)
@mock.patch('swiftclient.shell.walk') @mock.patch('swiftclient.shell.walk')
@mock.patch('swiftclient.service.Connection') @mock.patch('swiftclient.service.Connection')