Example #1
0
 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')
Example #2
0
 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)
Example #3
0
    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')
Example #4
0
    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)
Example #5
0
 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])
Example #6
0
 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
Example #7
0
 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))
Example #8
0
 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)
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 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