示例#1
0
def test_extract_http_response_content():
    response = Response()
    response.status_code = 200
    response.headers = {'Content-Type': 'application/json'}
    response_content = core.extract_http_response_content(response)

    assert all(key in response_content for key in ('status_code', ))
示例#2
0
def test_extract_http_response_content_check_for_json_key():
    response = Response()
    response.status_code = 200
    response.encoding = 'UTF-8'
    response._content = dumps({'content': True}).encode()
    response_content = core.extract_http_response_content(response)

    assert 'data' in response_content
示例#3
0
def test_extract_http_response_content_with_not_supported_argument_type():
    response = {
        'status_code': 200,
        'headers': {
            'Content-Type': 'application/json'
        },
        'body': '<h1>Hello, pyhttptest!</h1>'
    }
    response_content = core.extract_http_response_content(response)

    assert response_content is None
def execute_single_test_scenario(json_data):
    """Wrapper function that comprises functionalities
    to execute a single test scenario.

    :param dict json_data: An arbitrary data.

    :returns: Result of the test scenario.
    :rtype: `dict'
    """
    required_args, optional_kwargs = core.extract_json_data(json_data)
    http_method, url = core.prepare_request_args(*required_args)
    response = core.send_http_request(http_method, url, **optional_kwargs)
    response_content = core.extract_http_response_content(response)
    # Add a test case name as JSON property
    response_content['name'] = json_data['name']
    response_content['cover'] = ' % - COMING SOON'

    return response_content
示例#5
0
文件: cli.py 项目: gridl/pyhttptest
def execute(file):
    """Executes a test scenario from a given .json file format.

    The command executes an HTTP Request with a composed content from
    a given .json file, described in a specific format and prints out
    the result of an HTTP Response to the stdout.
    """
    try:
        json_file_data = core.load_json_from_file(file)
        required_args, optional_kwargs = core.extract_json_data(json_file_data)
        http_method, url = core.prepare_request_args(*required_args)
        response = core.send_http_request(http_method, url)
        response_content = core.extract_http_response_content(response)
        # Add a JSON property 'name' in the content
        response_content['name'] = json_file_data['name']
        core.printout_result(**response_content)
    except Exception as exc:
        click.echo(str(exc))

    return None