Don't use requests.Response object directly
In requests 1.2 Responses are assumed to always have a HTTPResponse object and it tries to extract headers from it. We solved this in the create_response function but we didn't use it in all our tests. Always use create_response when creating a custom matcher response. Change-Id: I979f74a64c6f5accf1b88dcc3e5e004131945dff Closes-Bug: #1361515
This commit is contained in:
parent
79cd58d9d1
commit
7ba4595f95
@ -28,14 +28,7 @@ class FailMatcher(object):
|
||||
|
||||
|
||||
def match_all(request):
|
||||
resp = requests.Response()
|
||||
resp.status_code = 200
|
||||
resp._content = six.b('data')
|
||||
resp.request = request
|
||||
resp.encoding = 'utf-8'
|
||||
resp.close = lambda *args, **kwargs: None
|
||||
|
||||
return resp
|
||||
return requests_mock.create_response(request, content=six.b('data'))
|
||||
|
||||
|
||||
def test_a(request):
|
||||
|
@ -14,6 +14,7 @@ import mock
|
||||
import requests
|
||||
|
||||
import requests_mock
|
||||
from requests_mock import compat
|
||||
from requests_mock.tests import base
|
||||
|
||||
original_send = requests.Session.send
|
||||
@ -54,8 +55,14 @@ class MockerTests(base.TestCase):
|
||||
def test_real_http(self, real_send, mocker):
|
||||
url = 'http://www.google.com/'
|
||||
|
||||
# NOTE(jamielennox): hack for requests 1.2.3 remove after
|
||||
# requirements catches up.
|
||||
class FakeHTTPResponse(object):
|
||||
_original_response = compat._fake_http_response
|
||||
|
||||
real_send.return_value = requests.Response()
|
||||
real_send.return_value.status_code = 200
|
||||
real_send.return_value.raw = FakeHTTPResponse()
|
||||
requests.get(url)
|
||||
|
||||
self.assertEqual(1, real_send.call_count)
|
||||
|
Loading…
x
Reference in New Issue
Block a user