Fix arguments' mess with init_http_request

* add named argument byte_range to HttpUrl
* fix arguments order for init_http_request

Change-Id: I6281951f636e8684385ca9f4448d118816aec7b9
Closes-Bug: #1536923
This commit is contained in:
Artur Svechnikov 2016-01-22 10:18:55 +03:00
parent 6c0801f2eb
commit 09cc10177a
3 changed files with 18 additions and 2 deletions

View File

@ -87,6 +87,22 @@ class TestHttpUrl(unittest2.TestCase):
for data in enumerate(httpurl):
self.assertEqual(content[data[0]], data[1])
@mock.patch.object(utils, 'init_http_request')
def test_httpurl_next_slow_connection(self, mock_req):
url = "http://fake_url"
content = ['fake content #1', '', 'fake content #2']
req_mock = mock.Mock(headers={'content-length': 30})
req_mock.raw.read.side_effect = content
mock_req.return_value = req_mock
http_url = au.HttpUrl(url)
for data in content:
if data:
self.assertEqual(data, next(http_url))
expected_calls = [mock.call(url),
mock.call(url, byte_range=len(content[0]))]
self.assertEqual(expected_calls, mock_req.call_args_list)
class TestGunzipStream(unittest2.TestCase):
def test_gunzip_stream_next(self):

View File

@ -110,7 +110,7 @@ class HttpUrl(Target):
except Exception as exc:
LOG.exception(exc)
self.response_obj = utils.init_http_request(
self.url, self.processed_bytes)
self.url, byte_range=self.processed_bytes)
continue
else:
self.processed_bytes += len(data)

View File

@ -222,7 +222,7 @@ def should_bypass_proxy(url, noproxy_addrs):
return False
def init_http_request(url, proxies=None, noproxy_addrs=None, byte_range=0):
def init_http_request(url, byte_range=0, proxies=None, noproxy_addrs=None):
LOG.debug("Trying to initialize http request object %s, byte range: %s",
url, byte_range)
if should_bypass_proxy(url, noproxy_addrs):