def test_rpc_client_http_req_propagates_method_fn_exception_1():
request = requests.Request(method='ANY', url='http://arbitrary/url')
# Need the mock so that the `.json()` method can be overridden
response = mock.create_autospec(requests.Response)
response.status_code = 403
response.reason = 'Forbidden'
response.request = request
response.json.side_effect = Exception('not JSON')
def method_fn(*args, **kwargs):
raise DCOSHTTPException(response)
rpc_client = rpcclient.RpcClient('http://base/url')
with pytest.raises(DCOSException) as e:
rpc_client.http_req(method_fn, 'some/path')
expected_message = rpcclient.RpcClient.response_error_message(
status_code=403,
reason='Forbidden',
request_method='ANY',
request_url='http://arbitrary/url',
json_body=None)
assert str(e).endswith(expected_message)
评论列表
文章目录