Add happy path tests for ResponseBodyIterator

Change-Id: I5e971b57a0591752e7fca76d0df78ce139308db5
This commit is contained in:
Brian Waldon
2012-09-11 16:22:56 -07:00
parent ff3060c067
commit 11e6aadf19
2 changed files with 19 additions and 1 deletions

View File

@@ -15,12 +15,14 @@
import httplib import httplib
import socket import socket
import StringIO
import unittest import unittest
import mox import mox
from glanceclient import exc from glanceclient import exc
from glanceclient.common import http from glanceclient.common import http
from tests import utils
class TestClient(unittest.TestCase): class TestClient(unittest.TestCase):
@@ -53,3 +55,11 @@ class TestClient(unittest.TestCase):
self.assertTrue(endpoint in comm_err.message, fail_msg) self.assertTrue(endpoint in comm_err.message, fail_msg)
finally: finally:
m.UnsetStubs() m.UnsetStubs()
class TestResponseBodyIterator(unittest.TestCase):
def test_iter_default_chunk_size_64k(self):
resp = utils.FakeResponse({}, StringIO.StringIO('X' * 98304))
iterator = http.ResponseBodyIterator(resp)
chunks = list(iterator)
self.assertEqual(chunks, ['X' * 65536, 'X' * 32768])

View File

@@ -40,11 +40,19 @@ class FakeAPI(object):
class FakeResponse(object): class FakeResponse(object):
def __init__(self, headers): def __init__(self, headers, body=None):
"""
:param headers: dict representing HTTP response headers
:param body: file-like object
"""
self.headers = headers self.headers = headers
self.body = body
def getheaders(self): def getheaders(self):
return copy.deepcopy(self.headers).items() return copy.deepcopy(self.headers).items()
def getheader(self, key, default): def getheader(self, key, default):
return self.headers.get(key, default) return self.headers.get(key, default)
def read(self, amt):
return self.body.read(amt)