summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/test_swiftclient.py6
-rw-r--r--test/unit/test_shell.py42
-rw-r--r--test/unit/test_swiftclient.py53
3 files changed, 75 insertions, 26 deletions
diff --git a/test/functional/test_swiftclient.py b/test/functional/test_swiftclient.py
index 91e31af..a5c1211 100644
--- a/test/functional/test_swiftclient.py
+++ b/test/functional/test_swiftclient.py
@@ -332,7 +332,7 @@ class TestFunctional(unittest.TestCase):
resp_chunk_size=resp_chunk_size)
data = next(body)
self.assertEqual(self.test_data[:resp_chunk_size], data)
- self.assertTrue(1, self.conn.attempts)
+ self.assertEqual(1, self.conn.attempts)
for chunk in body.resp:
# Flush remaining data from underlying response
# (simulate a dropped connection)
@@ -369,13 +369,13 @@ class TestFunctional(unittest.TestCase):
hdrs, body = self.conn.get_object(self.containername, self.objectname)
data = body
self.assertEqual(self.test_data, data)
- self.assertTrue(1, self.conn.attempts)
+ self.assertEqual(1, self.conn.attempts)
hdrs, body = self.conn.get_object(self.containername, self.objectname,
resp_chunk_size=0)
data = body
self.assertEqual(self.test_data, data)
- self.assertTrue(1, self.conn.attempts)
+ self.assertEqual(1, self.conn.attempts)
def test_post_account(self):
self.conn.post_account({'x-account-meta-data': 'Something'})
diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py
index 80c031e..98d73e9 100644
--- a/test/unit/test_shell.py
+++ b/test/unit/test_shell.py
@@ -907,6 +907,48 @@ class TestShell(unittest.TestCase):
query_string='multipart-manifest=put',
response_dict=mock.ANY)
+ @mock.patch('swiftclient.shell.walk')
+ @mock.patch('swiftclient.service.Connection')
+ def test_upload_skip_container_put(self, connection, walk):
+ connection.return_value.head_object.return_value = {
+ 'content-length': '0'}
+ connection.return_value.put_object.return_value = EMPTY_ETAG
+ connection.return_value.attempts = 0
+ argv = ["", "upload", "container", "--skip-container-put",
+ self.tmpfile, "-H", "X-Storage-Policy:one",
+ "--meta", "Color:Blue"]
+ swiftclient.shell.main(argv)
+ connection.return_value.put_container.assert_not_called()
+
+ connection.return_value.put_object.assert_called_with(
+ 'container',
+ self.tmpfile.lstrip('/'),
+ mock.ANY,
+ content_length=0,
+ headers={'x-object-meta-mtime': mock.ANY,
+ 'X-Storage-Policy': 'one',
+ 'X-Object-Meta-Color': 'Blue'},
+ response_dict={})
+
+ # Upload in segments
+ connection.return_value.head_container.return_value = {
+ 'x-storage-policy': 'one'}
+ argv = ["", "upload", "container", "--skip-container-put",
+ self.tmpfile, "-S", "10"]
+ with open(self.tmpfile, "wb") as fh:
+ fh.write(b'12345678901234567890')
+ swiftclient.shell.main(argv)
+ # Both base and segments container are assumed to exist already
+ connection.return_value.put_container.assert_not_called()
+ connection.return_value.put_object.assert_called_with(
+ 'container',
+ self.tmpfile.lstrip('/'),
+ '',
+ content_length=0,
+ headers={'x-object-manifest': mock.ANY,
+ 'x-object-meta-mtime': mock.ANY},
+ response_dict={})
+
@mock.patch('swiftclient.service.SwiftService.upload')
def test_upload_object_with_account_readonly(self, upload):
argv = ["", "upload", "container", self.tmpfile]
diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py
index ad2af50..ae3e76f 100644
--- a/test/unit/test_swiftclient.py
+++ b/test/unit/test_swiftclient.py
@@ -2130,30 +2130,37 @@ class TestConnection(MockHttpTest):
pass
c.sleep = quick_sleep
- # test retries
- conn = c.Connection('http://www.test.com/auth/v1.0', 'asdf', 'asdf',
- retry_on_ratelimit=True)
- code_iter = [200] + [498] * (conn.retries + 1)
- auth_resp_headers = {
- 'x-auth-token': 'asdf',
- 'x-storage-url': 'http://storage/v1/test',
- }
- c.http_connection = self.fake_http_connection(
- *code_iter, headers=auth_resp_headers)
- with self.assertRaises(c.ClientException) as exc_context:
- conn.head_account()
- self.assertIn('Account HEAD failed', str(exc_context.exception))
- self.assertEqual(conn.attempts, conn.retries + 1)
+ def test_status_code(code):
+ # test retries
+ conn = c.Connection('http://www.test.com/auth/v1.0',
+ 'asdf', 'asdf', retry_on_ratelimit=True)
+ code_iter = [200] + [code] * (conn.retries + 1)
+ auth_resp_headers = {
+ 'x-auth-token': 'asdf',
+ 'x-storage-url': 'http://storage/v1/test',
+ }
+ c.http_connection = self.fake_http_connection(
+ *code_iter, headers=auth_resp_headers)
+ with self.assertRaises(c.ClientException) as exc_context:
+ conn.head_account()
+ self.assertIn('Account HEAD failed', str(exc_context.exception))
+ self.assertEqual(code, exc_context.exception.http_status)
+ self.assertEqual(conn.attempts, conn.retries + 1)
- # test default no-retry
- c.http_connection = self.fake_http_connection(
- 200, 498,
- headers=auth_resp_headers)
- conn = c.Connection('http://www.test.com/auth/v1.0', 'asdf', 'asdf')
- with self.assertRaises(c.ClientException) as exc_context:
- conn.head_account()
- self.assertIn('Account HEAD failed', str(exc_context.exception))
- self.assertEqual(conn.attempts, 1)
+ # test default no-retry
+ c.http_connection = self.fake_http_connection(
+ 200, code,
+ headers=auth_resp_headers)
+ conn = c.Connection('http://www.test.com/auth/v1.0',
+ 'asdf', 'asdf', retry_on_ratelimit=False)
+ with self.assertRaises(c.ClientException) as exc_context:
+ conn.head_account()
+ self.assertIn('Account HEAD failed', str(exc_context.exception))
+ self.assertEqual(code, exc_context.exception.http_status)
+ self.assertEqual(conn.attempts, 1)
+
+ test_status_code(498)
+ test_status_code(429)
def test_retry_with_socket_error(self):
def quick_sleep(*args):