summaryrefslogtreecommitdiff
path: root/tests/test_utils.py
diff options
context:
space:
mode:
authormouad benchchaoui <m.benchchaoui@cloudbau.de>2013-07-08 21:18:16 +0200
committermouad benchchaoui <m.benchchaoui@cloudbau.de>2013-08-08 15:40:15 +0200
commit1d7da740b22945c43a9f36affca3c1b3fbad91fa (patch)
tree5abb69ba9d8f83e26b7fc3c106c72faf8c546aef /tests/test_utils.py
parent43e71e399372102f8ef4a3b7ad836fe16ace63a3 (diff)
downloadpython-glanceclient-1d7da740b22945c43a9f36affca3c1b3fbad91fa.tar.gz
Show a pretty progressbar when uploading and downloading an image.
Add a new module that contain generic wrapper for file and iterator, which are used to wrap image to upload and the request body iterator in upload and download cases repectively, to show and advance a pretty progress bar when this laters are consumed, The progress bar is triggered by adding a --progress command line argument to commands: image-create, image-download or image-update. Change-Id: I2ba42fd0c58f4fa087adb568ec3f08246cae3759 bug fix: LP#1112309 blueprint: progressbar-when-uploading
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py48
1 files changed, 23 insertions, 25 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index d47c7bb..fbcf8fb 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -13,39 +13,16 @@
# License for the specific language governing permissions and limitations
# under the License.
-import errno
-import testtools
import sys
import StringIO
+import testtools
+
from glanceclient.common import utils
class TestUtils(testtools.TestCase):
- def test_integrity_iter_without_checksum(self):
- try:
- data = ''.join([f for f in utils.integrity_iter('A', None)])
- self.fail('integrity checked passed without checksum.')
- except IOError as e:
- self.assertEqual(errno.EPIPE, e.errno)
- msg = 'was 7fc56270e7a70fa81a5935b72eacbe29 expected None'
- self.assertTrue(msg in str(e))
-
- def test_integrity_iter_with_wrong_checksum(self):
- try:
- data = ''.join([f for f in utils.integrity_iter('BB', 'wrong')])
- self.fail('integrity checked passed with wrong checksum')
- except IOError as e:
- self.assertEqual(errno.EPIPE, e.errno)
- msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
- self.assertTrue('expected wrong' in str(e))
-
- def test_integrity_iter_with_checksum(self):
- fixture = 'CCC'
- checksum = 'defb99e69a9f1f6e06f15006b1f166ae'
- data = ''.join([f for f in utils.integrity_iter(fixture, checksum)])
-
def test_make_size_human_readable(self):
self.assertEqual("106B", utils.make_size_human_readable(106))
self.assertEqual("1000kB", utils.make_size_human_readable(1024000))
@@ -53,6 +30,27 @@ class TestUtils(testtools.TestCase):
self.assertEqual("1.4GB", utils.make_size_human_readable(1476395008))
self.assertEqual("9.3MB", utils.make_size_human_readable(9761280))
+ def test_get_new_file_size(self):
+ size = 98304
+ file_obj = StringIO.StringIO('X' * size)
+ try:
+ self.assertEqual(utils.get_file_size(file_obj), size)
+ # Check that get_file_size didn't change original file position.
+ self.assertEqual(file_obj.tell(), 0)
+ finally:
+ file_obj.close()
+
+ def test_get_consumed_file_size(self):
+ size, consumed = 98304, 304
+ file_obj = StringIO.StringIO('X' * size)
+ file_obj.seek(consumed)
+ try:
+ self.assertEqual(utils.get_file_size(file_obj), size)
+ # Check that get_file_size didn't change original file position.
+ self.assertEqual(file_obj.tell(), consumed)
+ finally:
+ file_obj.close()
+
def test_prettytable(self):
class Struct:
def __init__(self, **entries):