def test_set_checksum_in_consumed_iterator(self): resp = utils.FakeResponse({}, six.BytesIO(b'CCC')) body = http.ResponseBodyIterator(resp) list(body) # Setting checksum for an already consumed iterator should raise an # AttributeError. self.assertRaises(AttributeError, body.set_checksum, 'defb99e69a9f1f6e06f15006b1f166ae')
def test_integrity_check_with_wrong_checksum(self): resp = utils.FakeResponse({}, six.BytesIO(b'BB')) body = http.ResponseBodyIterator(resp) body.set_checksum('wrong') try: list(body) self.fail('integrity checked passed with wrong checksum') except IOError as e: self.assertEqual(errno.EPIPE, e.errno)
def test_image_download(self): args = self._make_args({ 'id': 'pass', 'file': 'test', 'progress': False }) with mock.patch.object(self.gc.images, 'data') as mocked_data: resp = test_utils.FakeResponse({}, StringIO.StringIO('CCC')) ret = mocked_data.return_value = http.ResponseBodyIterator(resp) test_shell.do_image_download(self.gc, args) mocked_data.assert_called_once_with('pass') utils.save_image.assert_called_once_with(ret, 'test')
def test_image_download_with_progressbar(self): args = self._make_args({ 'id': 'pass', 'file': 'test', 'progress': True }) with mock.patch.object(self.gc.images, 'data') as mocked_data: resp = test_utils.FakeResponse({}, StringIO.StringIO('CCC')) mocked_data.return_value = http.ResponseBodyIterator(resp) test_shell.do_image_download(self.gc, args) mocked_data.assert_called_once_with('pass') utils.save_image.assert_called_once_with(mock.ANY, 'test') self.assertIsInstance(utils.save_image.call_args[0][0], progressbar.VerboseIteratorWrapper)
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])
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
def test_body_size(self): size = 1000000007 resp = utils.FakeResponse({'content-length': str(size)}, six.BytesIO(b'BB')) body = http.ResponseBodyIterator(resp) self.assertEqual(size, len(body))
def test_integrity_check_with_correct_checksum(self): resp = utils.FakeResponse({}, six.BytesIO(b'CCC')) body = http.ResponseBodyIterator(resp) body.set_checksum('defb99e69a9f1f6e06f15006b1f166ae') list(body)
def test_iter_default_chunk_size_64k(self): resp = utils.FakeResponse({}, six.BytesIO(b'X' * 98304)) iterator = http.ResponseBodyIterator(resp) chunks = list(iterator) self.assertEqual([b'X' * 65536, b'X' * 32768], chunks)
def test_body_size(self): size = 1000000007 resp = utils.FakeResponse({'content-length': str(size)}, StringIO.StringIO('BB')) body = http.ResponseBodyIterator(resp) self.assertEqual(len(body), size)
def raw_request(self, *args, **kwargs): fixture = self._request(*args, **kwargs) resp = FakeResponse(fixture[0], six.StringIO(fixture[1])) body_iter = http.ResponseBodyIterator(resp) return resp, body_iter