Prevent test runs from cluttering current directory

Previously, the following empty directories would be created:
  * container
  * container/pseudo
  * pseudo

Change-Id: I002e2da8d28a873728e0b5c2d33f94f21132d058
This commit is contained in:
Tim Burke 2016-01-19 14:26:13 -08:00
parent 64c2c2eaaa
commit 38f9664167

@ -345,6 +345,8 @@ class TestShell(testtools.TestCase):
connection.return_value.get_object.assert_has_calls(
calls, any_order=True)
mock_open.assert_called_once_with('object', 'wb')
self.assertEqual([mock.call('pseudo')], makedirs.mock_calls)
makedirs.reset_mock()
# Test downloading single object
objcontent = six.BytesIO(b'objcontent')
@ -360,6 +362,7 @@ class TestShell(testtools.TestCase):
'container', 'object', headers={}, resp_chunk_size=65536,
response_dict={})
mock_open.assert_called_with('object', 'wb')
self.assertEqual([], makedirs.mock_calls)
# Test downloading single object to stdout
objcontent = six.BytesIO(b'objcontent')
@ -396,6 +399,7 @@ class TestShell(testtools.TestCase):
]
with mock.patch(BUILTIN_OPEN) as mock_open:
with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
argv = ["", "download", "--all"]
swiftclient.shell.main(argv)
self.assertEqual(3, mock_shuffle.call_count)
@ -403,6 +407,10 @@ class TestShell(testtools.TestCase):
mock_shuffle.assert_any_call(['object'])
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
mock_shuffle.reset_mock()
@ -418,10 +426,15 @@ class TestShell(testtools.TestCase):
]
with mock.patch(BUILTIN_OPEN) as mock_open:
with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
argv = ["", "download", "--all", "--no-shuffle"]
swiftclient.shell.main(argv)
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')
def test_download_no_content_type(self, connection):
@ -439,6 +452,7 @@ class TestShell(testtools.TestCase):
connection.return_value.attempts = 0
with mock.patch(BUILTIN_OPEN) as mock_open:
with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
argv = ["", "download", "container"]
swiftclient.shell.main(argv)
calls = [mock.call('container', 'object',
@ -450,6 +464,9 @@ class TestShell(testtools.TestCase):
connection.return_value.get_object.assert_has_calls(
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.service.Connection')