def call(method, api_or_module, url, body='', headers=None, **params):
    """Simulates a round-trip call against the given API / URL"""
    api = API(api_or_module).http.server()
    response = StartResponseMock()
    headers = {} if headers is None else headers
    if not isinstance(body, str) and 'json' in headers.get('content-type', 'application/json'):
        body = output_format.json(body)
        headers.setdefault('content-type', 'application/json')

    result = api(create_environ(path=url, method=method, headers=headers, query_string=urlencode(params, True),
                                body=body),
                 response)
    if result:
        try:
            response.data = result[0].decode('utf8')
        except __HOLE__:
            response.data = []
            for chunk in result:
                response.data.append(chunk.decode('utf8'))
            response.data = "".join(response.data)
        except UnicodeDecodeError:
            response.data = result[0]
        response.content_type = response.headers_dict['content-type']
        if response.content_type == 'application/json':
            response.data = json.loads(response.data)

    return response
dataset/ETHPy150Open timothycrosley/hug/hug/test.py/call