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
예제 #2
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
예제 #3
0
def test_extract_json_data_with_key_name_response():
    content = core.load_content_from_json_file(
        'data/HTTP_GET_SAVE_RESPONSE.json')
    required_args, optional_kwargs = core.extract_json_data(content[0])

    assert 'response' in optional_kwargs and optional_kwargs['response']
예제 #4
0
def test_extract_json_data():
    content = core.load_content_from_json_file('data/HTTP_GET.json')
    required_args, optional_kwargs = core.extract_json_data(content[0])

    assert isinstance(required_args, tuple) and isinstance(
        optional_kwargs, dict)