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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
def test_prepare_request_args_with_invalid_arguments():
    args = ('users', 'http://localhost:8080')
    request_args = core.prepare_request_args(*args)

    assert request_args is None
Ejemplo n.º 4
0
def test_prepare_request_args():
    args = ('TEST: List all users', 'GET', 'users', 'http://localhost:8080')
    request_args = core.prepare_request_args(*args)
    expected_args = ('get', 'http://localhost:8080/users')

    assert sorted(request_args) == sorted(expected_args)