summaryrefslogtreecommitdiff
path: root/tests/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/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/utils.py')
-rw-r--r--tests/utils.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 0202a42..3d85951 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -33,8 +33,9 @@ class FakeAPI(object):
def raw_request(self, *args, **kwargs):
fixture = self._request(*args, **kwargs)
- body_iter = http.ResponseBodyIterator(StringIO.StringIO(fixture[1]))
- return FakeResponse(fixture[0]), body_iter
+ resp = FakeResponse(fixture[0], StringIO.StringIO(fixture[1]))
+ body_iter = http.ResponseBodyIterator(resp)
+ return resp, body_iter
def json_request(self, *args, **kwargs):
fixture = self._request(*args, **kwargs)
@@ -95,3 +96,17 @@ class TestResponse(requests.Response):
@property
def text(self):
return self._text
+
+
+class FakeTTYStdout(StringIO.StringIO):
+ """A Fake stdout that try to emulate a TTY device as much as possible."""
+
+ def isatty(self):
+ return True
+
+ def write(self, data):
+ # When a CR (carriage return) is found reset file.
+ if data.startswith('\r'):
+ self.seek(0)
+ data = data[1:]
+ return StringIO.StringIO.write(self, data)