zulip_bots: Use real Response object for mock_http_conversation().

This commit is contained in:
Robert Hönig 2017-11-27 15:58:31 +01:00 committed by showell
parent 41d8ffc20e
commit 93edededdd

View file

@ -136,12 +136,9 @@ class BotTestCaseBase(TestCase):
http_response = http_data.get('response') http_response = http_data.get('response')
http_headers = http_data.get('response-headers') http_headers = http_data.get('response-headers')
with patch('requests.get') as mock_get: with patch('requests.get') as mock_get:
mock_result = mock.MagicMock() mock_result = requests.Response()
mock_result.json.return_value = http_response mock_result._content = json.dumps(http_response).encode()
if 'text' in http_response:
mock_result.text = http_response.get('text', None)
mock_result.status_code = http_headers.get('status', 200) mock_result.status_code = http_headers.get('status', 200)
mock_result.ok.return_value = http_headers.get('ok', True)
mock_get.return_value = mock_result mock_get.return_value = mock_result
yield yield
if 'params' in http_request: if 'params' in http_request: