test_marathon.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:deb-python-dcos 作者: openstack 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号