예제 #1
0
파일: printer.py 프로젝트: gridl/pyhttptest
def prepare_data_for_print(**kwargs):
    """Wrapper function responsible to take the data, push it
    through several processes to prepare it for print.

    :param kwargs: Data in format key/value.

    :returns: Data for print.
    :rtype: `str`
    """
    args = extract_properties_values_from_json(kwargs,
                                               PRINTER_HEADERS_DATA_KEYS)
    sliced_str_args = _slice_str_args(*args)

    return _format_data_as_tabular(*sliced_str_args)
예제 #2
0
def test_extract_properties_values_from_json():
    json_data = {
        'name': 'TEST: List all users',
        'verb': 'GET',
        'endpoint': 'users',
        'host': 'http://localhost:8080',
        'headers': {
            'Accept-Language': 'en-US'
        }
    }
    json_keys = ('verb', 'endpoint', 'host')
    extracted_keys_values = utils.extract_properties_values_from_json(
        json_data, json_keys)
    expected_keys_values = (json_data['verb'], json_data['endpoint'],
                            json_data['host'])

    assert sorted(expected_keys_values) == sorted(extracted_keys_values)
예제 #3
0
파일: core.py 프로젝트: gridl/pyhttptest
def extract_json_data(data):
    """Wrapper function that extracts JSON data.

    By passing ``data`` parameter, the JSON content
    from parameter is extracted under the required
    and optional keys.

    :param dict data: An arbitrary data.

    :returns: Splitted data into required and optional.
    :rtype: `tuple`
    """
    required_args = utils.extract_properties_values_from_json(
        data, constants.REQUIRED_SCHEMA_KEYS)
    optional_kwargs = utils.extract_properties_values_of_type_dict_from_json(
        data, constants.OPTIONAL_SCHEMA_KEYS)

    return (required_args, optional_kwargs)
def prepare_data_for_print(list_of_dicts):
    """Wrapper function responsible to take the data, push it
    through several processes to prepare it for print.

    :param list list_of_dicts: List of `dict` data.

    :returns: Data for print.
    :rtype: `str`
    """
    list_of_strs = []

    for _dict in list_of_dicts:
        args = extract_properties_values_from_json(_dict,
                                                   PRINTER_HEADERS_DATA_KEYS)
        sliced_str_args = _slice_str_args(*args)
        list_of_strs.append(sliced_str_args)

    return _format_data_as_tabular(list_of_strs)