summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Wakefield <daniel.wakefield@hp.com>2014-10-06 15:24:19 +0100
committerDaniel Wakefield <daniel.wakefield@hp.com>2014-10-10 12:57:35 +0100
commit5f89dcc46ea0ae126c9ebc328d6569da839336cd (patch)
treec60cd64cc0d604015bae4a0cdb865f65ba538149 /tests
parentbb4d2ab59c4de9389667eeed255642f51e276f1e (diff)
downloadpython-swiftclient-5f89dcc46ea0ae126c9ebc328d6569da839336cd.tar.gz
Allow segment size to be specified in a human readable way.
Instead of always specifying segment size in bytes the user can now use B,K,M or G as suffixes for the corresponding size. Conversion is done with Binary units (1024) rather than SI units (1000). e.g swift upload test_container -S 1073741824 large_file can now be written swift upload test_container -S 1G large_file The change is backwards compatible as it ignores arguments to -S that don't have a valid suffix. Updated unit tests and help message. Change-Id: I6314b4e45cf2fbffde2fe57a02df77a25e911e84
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_shell.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index 78da0dd..fba2b73 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -408,6 +408,56 @@ class TestShell(unittest.TestCase):
swiftclient.shell.main(argv)
connection.return_value.get_capabilities.assert_called_with(None)
+ def test_human_readable_upload_segment_size(self):
+ def _check_expected(x, expected):
+ actual = x.call_args_list[-1][1]["options"]["segment_size"]
+ self.assertEqual(int(actual), expected)
+
+ mock_out = mock.MagicMock(spec=swiftclient.shell.OutputManager)
+ mock_out.__enter__.return_value = mock_out
+ mock_out.return_value = mock_out
+ type(mock_out).error_count = mock.PropertyMock(return_value=0)
+
+ mock_swift = mock.MagicMock(spec=swiftclient.shell.SwiftService)
+
+ with mock.patch("swiftclient.shell.SwiftService", mock_swift):
+ with mock.patch('swiftclient.shell.OutputManager', mock_out):
+ # Test new behaviour with both upper and lower case
+ # trailing characters
+ argv = ["", "upload", "-S", "1B", "container", "object"]
+ swiftclient.shell.main(argv)
+ _check_expected(mock_swift, 1)
+
+ argv = ["", "upload", "-S", "1K", "container", "object"]
+ swiftclient.shell.main(argv)
+ _check_expected(mock_swift, 1024)
+
+ argv = ["", "upload", "-S", "1m", "container", "object"]
+ swiftclient.shell.main(argv)
+ _check_expected(mock_swift, 1048576)
+
+ argv = ["", "upload", "-S", "1G", "container", "object"]
+ swiftclient.shell.main(argv)
+ _check_expected(mock_swift, 1073741824)
+
+ # Test old behaviour is not affected
+ argv = ["", "upload", "-S", "12345", "container", "object"]
+ swiftclient.shell.main(argv)
+ _check_expected(mock_swift, 12345)
+
+ # Test invalid states
+ argv = ["", "upload", "-S", "1234X", "container", "object"]
+ swiftclient.shell.main(argv)
+ mock_out.error.assert_called_with("Invalid segment size")
+
+ argv = ["", "upload", "-S", "K1234", "container", "object"]
+ swiftclient.shell.main(argv)
+ mock_out.error.assert_called_with("Invalid segment size")
+
+ argv = ["", "upload", "-S", "K", "container", "object"]
+ swiftclient.shell.main(argv)
+ mock_out.error.assert_called_with("Invalid segment size")
+
class TestSubcommandHelp(unittest.TestCase):