Commit e991194c authored by Stephen Finucane's avatar Stephen Finucane
Browse files

Don't use 'requests.PreparedRequest'

We're using 'requests.PreparedRequest' in one place in the tests.
However, the requests docs have a warning that one shouldn't do this:

  Instances are generated from a Request object, and should not be
  instantiated manually; doing so may produce undesirable effects.

It seems we're now seeing just such an effect, as requests has started
attempting to do proxy-related things resulting in the following error:

    Traceback (most recent call last):
      File "/usr/lib64/python3.6/unittest/mock.py", line 1183, in patched
    return func(*args, **keywargs)
      File ".../oslo.vmware/oslo_vmware/tests/test_service.py", line 518, in test_send_with_local_file_url
    resp = transport.session.send(request)
      File ".../oslo.vmware/.tox/py36/lib/python3.6/site-packages/requests/sessions.py", line 636, in send
    kwargs.setdefault('proxies', self.rebuild_proxies(request, self.proxies))
      File ".../oslo.vmware/.tox/py36/lib/python3.6/site-packages/requests/sessions....
parent a2e76d64
......@@ -493,8 +493,7 @@ class RequestsTransportTest(base.TestCase):
transport = service.RequestsTransport()
url = 'file:///foo'
request = requests.PreparedRequest()
request.url = url
request = requests.Request('GET', url).prepare()
data = b"Hello World"
get_size_mock.return_value = len(data)
......@@ -502,7 +501,6 @@ class RequestsTransportTest(base.TestCase):
def read_mock():
return data
builtin_open = 'builtins.open'
open_mock = mock.MagicMock(name='file_handle',
spec=open)
file_spec = list(set(dir(io.TextIOWrapper)).union(
......@@ -514,7 +512,7 @@ class RequestsTransportTest(base.TestCase):
file_handle.read.side_effect = read_mock
open_mock.return_value = file_handle
with mock.patch(builtin_open, open_mock, create=True):
with mock.patch('builtins.open', open_mock, create=True):
resp = transport.session.send(request)
self.assertEqual(data, resp.content)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment