import json


def _test_response(
    client,
    req_method,
    url,
    headers,
    data,
    expected_resp_code,
    input_stream=None,
):
    """Util function testing response code."""
    kwargs = {}
    if input_stream:
        kwargs["input_stream"] = input_stream
    if data:
        res = getattr(client, req_method)(
            url, headers=headers, data=json.dumps(data), **kwargs
        )
    else:
        res = getattr(client, req_method)(url, headers=headers, **kwargs)
    assert expected_resp_code == res.status_code
    return res