Merge "Check that content_type header exists before using"
This commit is contained in:
commit
7709fea51e
@ -1012,7 +1012,8 @@ class SwiftService(object):
|
|||||||
try:
|
try:
|
||||||
no_file = options['no_download']
|
no_file = options['no_download']
|
||||||
content_type = headers.get('content-type')
|
content_type = headers.get('content-type')
|
||||||
if content_type.split(';', 1)[0] == 'text/directory':
|
if (content_type and
|
||||||
|
content_type.split(';', 1)[0] == 'text/directory'):
|
||||||
make_dir = not no_file and out_file != "-"
|
make_dir = not no_file and out_file != "-"
|
||||||
if make_dir and not isdir(path):
|
if make_dir and not isdir(path):
|
||||||
mkdirs(path)
|
mkdirs(path)
|
||||||
|
@ -326,6 +326,34 @@ class TestShell(unittest.TestCase):
|
|||||||
response_dict={})
|
response_dict={})
|
||||||
mock_open.assert_called_with('object', 'wb')
|
mock_open.assert_called_with('object', 'wb')
|
||||||
|
|
||||||
|
@mock.patch('swiftclient.service.Connection')
|
||||||
|
def test_download_no_content_type(self, connection):
|
||||||
|
connection.return_value.get_object.return_value = [
|
||||||
|
{'etag': 'd41d8cd98f00b204e9800998ecf8427e'},
|
||||||
|
'']
|
||||||
|
|
||||||
|
# Test downloading whole container
|
||||||
|
connection.return_value.get_container.side_effect = [
|
||||||
|
[None, [{'name': 'object'}]],
|
||||||
|
[None, [{'name': 'pseudo/'}]],
|
||||||
|
[None, []],
|
||||||
|
]
|
||||||
|
connection.return_value.auth_end_time = 0
|
||||||
|
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')
|
||||||
|
|
||||||
@mock.patch('swiftclient.shell.walk')
|
@mock.patch('swiftclient.shell.walk')
|
||||||
@mock.patch('swiftclient.service.Connection')
|
@mock.patch('swiftclient.service.Connection')
|
||||||
def test_upload(self, connection, walk):
|
def test_upload(self, connection, walk):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user