Add happy path tests for ResponseBodyIterator
Change-Id: I5e971b57a0591752e7fca76d0df78ce139308db5
This commit is contained in:
		@@ -15,12 +15,14 @@
 | 
			
		||||
 | 
			
		||||
import httplib
 | 
			
		||||
import socket
 | 
			
		||||
import StringIO
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
import mox
 | 
			
		||||
 | 
			
		||||
from glanceclient import exc
 | 
			
		||||
from glanceclient.common import http
 | 
			
		||||
from tests import utils
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestClient(unittest.TestCase):
 | 
			
		||||
@@ -53,3 +55,11 @@ class TestClient(unittest.TestCase):
 | 
			
		||||
            self.assertTrue(endpoint in comm_err.message, fail_msg)
 | 
			
		||||
        finally:
 | 
			
		||||
            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])
 | 
			
		||||
 
 | 
			
		||||
@@ -40,11 +40,19 @@ class FakeAPI(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.body = body
 | 
			
		||||
 | 
			
		||||
    def getheaders(self):
 | 
			
		||||
        return copy.deepcopy(self.headers).items()
 | 
			
		||||
 | 
			
		||||
    def getheader(self, key, default):
 | 
			
		||||
        return self.headers.get(key, default)
 | 
			
		||||
 | 
			
		||||
    def read(self, amt):
 | 
			
		||||
        return self.body.read(amt)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user