test_offers_handler.py 文件源码

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

项目:query-srv 作者: openpermissions 项目源码 文件源码
def test_post_with_bad_data(service_client, get_repositories, get_repository):
    get_repositories.return_value = future_repositories
    get_repository.return_value = future_repository

    mock_response = Mock()
    mock_response.body = '{"errors": [{"source_id_type": "", "message": "not supported asset id type"}]}'
    mock_response.code = 400
    exc = httpclient.HTTPError(400, response=mock_response)
    service_client.return_value = make_future(MagicMock())
    client = yield service_client()
    endpoint = client.repository.repositories[''].search.offers
    endpoint.post.side_effect = exc

    handler = _create_offers_handler()

    # MUT
    handler.request.body = ('[{"source_id":' +
                            '"https://openpermissions.org/s0/hub1/asset/exampleco/ExampleCoPictureID/1",' +
                            '"source_id_type":""}]')

    with pytest.raises(HTTPError) as excinfo:
        handler.post().result()

    assert excinfo.value.status_code == mock_response.code
    assert excinfo.value.errors == json.loads(mock_response.body)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号