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)
评论列表
文章目录