summaryrefslogtreecommitdiff
path: root/tests/unit/test_shell.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2016-01-19 14:26:13 -0800
committerTim Burke <tim.burke@gmail.com>2016-01-19 14:26:13 -0800
commit38f96641671fff670eaae99b7b6f6fcd902438e2 (patch)
tree402c40a86cf9821b4ec3db6291ed7524cc65fef8 /tests/unit/test_shell.py
parent64c2c2eaaae630da67653aaf18ad9ea319af1baa (diff)
downloadpython-swiftclient-38f96641671fff670eaae99b7b6f6fcd902438e2.tar.gz
Prevent test runs from cluttering current directory
Previously, the following empty directories would be created: * container * container/pseudo * pseudo Change-Id: I002e2da8d28a873728e0b5c2d33f94f21132d058
Diffstat (limited to 'tests/unit/test_shell.py')
-rw-r--r--tests/unit/test_shell.py87
1 files changed, 52 insertions, 35 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index 662fbcc..6e473e3 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -336,15 +336,17 @@ class TestShell(testtools.TestCase):
with mock.patch(BUILTIN_OPEN) as mock_open:
argv = ["", "download", "container"]
swiftclient.shell.main(argv)
- calls = [mock.call('container', 'object',
- headers={}, resp_chunk_size=65536,
- response_dict={}),
- mock.call('container', 'pseudo/',
- headers={}, resp_chunk_size=65536,
- response_dict={})]
- connection.return_value.get_object.assert_has_calls(
- calls, any_order=True)
- mock_open.assert_called_once_with('object', 'wb')
+ calls = [mock.call('container', 'object',
+ headers={}, resp_chunk_size=65536,
+ response_dict={}),
+ mock.call('container', 'pseudo/',
+ headers={}, resp_chunk_size=65536,
+ response_dict={})]
+ 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')
@@ -356,10 +358,11 @@ class TestShell(testtools.TestCase):
with mock.patch(BUILTIN_OPEN) as mock_open:
argv = ["", "download", "container", "object"]
swiftclient.shell.main(argv)
- connection.return_value.get_object.assert_called_with(
- 'container', 'object', headers={}, resp_chunk_size=65536,
- response_dict={})
- mock_open.assert_called_with('object', 'wb')
+ connection.return_value.get_object.assert_called_with(
+ '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,13 +399,18 @@ class TestShell(testtools.TestCase):
]
with mock.patch(BUILTIN_OPEN) as mock_open:
- argv = ["", "download", "--all"]
- swiftclient.shell.main(argv)
- self.assertEqual(3, mock_shuffle.call_count)
- mock_shuffle.assert_any_call(['container'])
- mock_shuffle.assert_any_call(['object'])
- mock_shuffle.assert_any_call(['pseudo/'])
- mock_open.assert_called_once_with('container/object', 'wb')
+ with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
+ argv = ["", "download", "--all"]
+ swiftclient.shell.main(argv)
+ self.assertEqual(3, mock_shuffle.call_count)
+ mock_shuffle.assert_any_call(['container'])
+ 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:
- 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')
+ 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,17 +452,21 @@ class TestShell(testtools.TestCase):
connection.return_value.attempts = 0
with mock.patch(BUILTIN_OPEN) as mock_open:
- argv = ["", "download", "container"]
- swiftclient.shell.main(argv)
- calls = [mock.call('container', 'object',
- headers={}, resp_chunk_size=65536,
- response_dict={}),
- mock.call('container', 'pseudo/',
- headers={}, resp_chunk_size=65536,
- response_dict={})]
- connection.return_value.get_object.assert_has_calls(
- calls, any_order=True)
- mock_open.assert_called_once_with('object', 'wb')
+ with mock.patch('swiftclient.service.makedirs') as mock_mkdir:
+ argv = ["", "download", "container"]
+ swiftclient.shell.main(argv)
+ calls = [mock.call('container', 'object',
+ headers={}, resp_chunk_size=65536,
+ response_dict={}),
+ mock.call('container', 'pseudo/',
+ headers={}, resp_chunk_size=65536,
+ response_dict={})]
+ 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')