Merge "Add tests for thread option validation"
This commit is contained in:
commit
c26dec66f6
@ -762,6 +762,37 @@ class TestShell(unittest.TestCase):
|
|||||||
'x-object-meta-mtime': mock.ANY},
|
'x-object-meta-mtime': mock.ANY},
|
||||||
response_dict={})
|
response_dict={})
|
||||||
|
|
||||||
|
@mock.patch.object(swiftclient.service.SwiftService, '_should_bulk_delete',
|
||||||
|
lambda *a: False)
|
||||||
|
@mock.patch('swiftclient.service.Connection')
|
||||||
|
def test_delete_bad_threads(self, mock_connection):
|
||||||
|
mock_connection.return_value.get_container.return_value = (None, [])
|
||||||
|
mock_connection.return_value.attempts = 0
|
||||||
|
|
||||||
|
def check_bad(argv):
|
||||||
|
args, env = _make_cmd(
|
||||||
|
'delete', {}, {}, cmd_args=['cont'] + argv)
|
||||||
|
with mock.patch.dict(os.environ, env):
|
||||||
|
with CaptureOutput() as output:
|
||||||
|
self.assertRaises(SystemExit, swiftclient.shell.main, args)
|
||||||
|
self.assertIn(
|
||||||
|
'ERROR: option %s should be a positive integer.' % argv[0],
|
||||||
|
output.err)
|
||||||
|
|
||||||
|
def check_good(argv):
|
||||||
|
args, env = _make_cmd(
|
||||||
|
'delete', {}, {}, cmd_args=['cont'] + argv)
|
||||||
|
with mock.patch.dict(os.environ, env):
|
||||||
|
with CaptureOutput() as output:
|
||||||
|
swiftclient.shell.main(args)
|
||||||
|
self.assertEqual('', output.err)
|
||||||
|
check_bad(["--object-threads", "-1"])
|
||||||
|
check_bad(["--object-threads", "0"])
|
||||||
|
check_bad(["--container-threads", "-1"])
|
||||||
|
check_bad(["--container-threads", "0"])
|
||||||
|
check_good(["--object-threads", "1"])
|
||||||
|
check_good(["--container-threads", "1"])
|
||||||
|
|
||||||
@mock.patch.object(swiftclient.service.SwiftService, '_should_bulk_delete',
|
@mock.patch.object(swiftclient.service.SwiftService, '_should_bulk_delete',
|
||||||
lambda *a: False)
|
lambda *a: False)
|
||||||
@mock.patch('swiftclient.service.Connection')
|
@mock.patch('swiftclient.service.Connection')
|
||||||
@ -2227,6 +2258,38 @@ class TestCrossAccountObjectAccess(TestBase, MockHttpTest):
|
|||||||
return status
|
return status
|
||||||
return on_request
|
return on_request
|
||||||
|
|
||||||
|
@mock.patch.object(swiftclient.service.SwiftService, '_should_bulk_delete',
|
||||||
|
lambda *a: False)
|
||||||
|
@mock.patch('swiftclient.service.Connection')
|
||||||
|
def test_upload_bad_threads(self, mock_connection):
|
||||||
|
mock_connection.return_value.put_object.return_value = EMPTY_ETAG
|
||||||
|
mock_connection.return_value.attempts = 0
|
||||||
|
|
||||||
|
def check_bad(argv):
|
||||||
|
args, env = self._make_cmd(
|
||||||
|
'upload', cmd_args=[self.cont, self.obj] + argv)
|
||||||
|
with mock.patch.dict(os.environ, env):
|
||||||
|
with CaptureOutput() as output:
|
||||||
|
self.assertRaises(SystemExit, swiftclient.shell.main, args)
|
||||||
|
self.assertIn(
|
||||||
|
'ERROR: option %s should be a positive integer.' % argv[0],
|
||||||
|
output.err)
|
||||||
|
|
||||||
|
def check_good(argv):
|
||||||
|
args, env = self._make_cmd(
|
||||||
|
'upload',
|
||||||
|
cmd_args=[self.cont, self.obj, '--leave-segments'] + argv)
|
||||||
|
with mock.patch.dict(os.environ, env):
|
||||||
|
with CaptureOutput() as output:
|
||||||
|
swiftclient.shell.main(args)
|
||||||
|
self.assertEqual('', output.err)
|
||||||
|
check_bad(["--object-threads", "-1"])
|
||||||
|
check_bad(["--object-threads", "0"])
|
||||||
|
check_bad(["--segment-threads", "-1"])
|
||||||
|
check_bad(["--segment-threads", "0"])
|
||||||
|
check_good(["--object-threads", "1"])
|
||||||
|
check_good(["--segment-threads", "1"])
|
||||||
|
|
||||||
def test_upload_with_read_write_access(self):
|
def test_upload_with_read_write_access(self):
|
||||||
req_handler = self._fake_cross_account_auth(True, True)
|
req_handler = self._fake_cross_account_auth(True, True)
|
||||||
fake_conn = self.fake_http_connection(403, 403,
|
fake_conn = self.fake_http_connection(403, 403,
|
||||||
@ -2378,6 +2441,38 @@ class TestCrossAccountObjectAccess(TestBase, MockHttpTest):
|
|||||||
self.assertTrue(expected_err in out.err)
|
self.assertTrue(expected_err in out.err)
|
||||||
self.assertEqual('', out)
|
self.assertEqual('', out)
|
||||||
|
|
||||||
|
@mock.patch.object(swiftclient.service.SwiftService, '_should_bulk_delete',
|
||||||
|
lambda *a: False)
|
||||||
|
@mock.patch('swiftclient.service.Connection')
|
||||||
|
def test_download_bad_threads(self, mock_connection):
|
||||||
|
mock_connection.return_value.get_object.return_value = [{}, '']
|
||||||
|
mock_connection.return_value.attempts = 0
|
||||||
|
|
||||||
|
def check_bad(argv):
|
||||||
|
args, env = self._make_cmd(
|
||||||
|
'download', cmd_args=[self.cont, self.obj] + argv)
|
||||||
|
with mock.patch.dict(os.environ, env):
|
||||||
|
with CaptureOutput() as output:
|
||||||
|
self.assertRaises(SystemExit, swiftclient.shell.main, args)
|
||||||
|
self.assertIn(
|
||||||
|
'ERROR: option %s should be a positive integer.' % argv[0],
|
||||||
|
output.err)
|
||||||
|
|
||||||
|
def check_good(argv):
|
||||||
|
args, env = self._make_cmd(
|
||||||
|
'download',
|
||||||
|
cmd_args=[self.cont, self.obj, '--no-download'] + argv)
|
||||||
|
with mock.patch.dict(os.environ, env):
|
||||||
|
with CaptureOutput() as output:
|
||||||
|
swiftclient.shell.main(args)
|
||||||
|
self.assertEqual('', output.err)
|
||||||
|
check_bad(["--object-threads", "-1"])
|
||||||
|
check_bad(["--object-threads", "0"])
|
||||||
|
check_bad(["--container-threads", "-1"])
|
||||||
|
check_bad(["--container-threads", "0"])
|
||||||
|
check_good(["--object-threads", "1"])
|
||||||
|
check_good(["--container-threads", "1"])
|
||||||
|
|
||||||
def test_download_with_read_write_access(self):
|
def test_download_with_read_write_access(self):
|
||||||
req_handler = self._fake_cross_account_auth(True, True)
|
req_handler = self._fake_cross_account_auth(True, True)
|
||||||
fake_conn = self.fake_http_connection(403, on_request=req_handler,
|
fake_conn = self.fake_http_connection(403, on_request=req_handler,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user