コード例 #1
0
def exact_check(context, json_path, exp_value):
    data = context.resp.json()
    logger.debug(data)
    actual_value = jpath.get(json_path, data)
    logger.debug("Actual value from response: {}".format(actual_value))
    assert str(actual_value) == str(
        exp_value), "Mismatch found Exp value :{}, Actual value: {}".format(
            exp_value, actual_value)
    logger.info("Pattern \"{}\" found in response".format(exp_value))
コード例 #2
0
ファイル: rest.py プロジェクト: aldefalco/webguide
def poll_GET(context, url_path_segment, jsonpath):
    json_value = json.loads(context.data)
    url = context.server.add_path_segment(url_path_segment)
    for i in range(context.n_attempts):
        response = requests.get(url, headers=context.headers, auth=context.auth)
        if jpath.get(jsonpath, response.json) == json_value:
            return
        time.sleep(context.pause_between_attempts)
    raise AssertionError(
        'Condition not met after %d attempts' % context.n_attempts)
コード例 #3
0
ファイル: __init__.py プロジェクト: stanfy/behave-rest
def json_object_validation(context, json_path, expected_json_value):
    data = context.r.json()
    actual_json_value = jpath.get(json_path, data)

    if expected_json_value.startswith("context"):
        expected_json_value = getattr(context, expected_json_value[8:])
        nose.tools.assert_equal(actual_json_value, expected_json_value)

    else:
        converted_value = json.loads(expected_json_value)
        nose.tools.assert_equal(actual_json_value, converted_value)
コード例 #4
0
def json_object_validation(context, json_path, expected_json_value):
    data = context.r.json()
    actual_json_value = jpath.get(json_path, data)

    if expected_json_value.startswith("context"):
        expected_json_value = getattr(context, expected_json_value[8:])
        nose.tools.assert_equal(actual_json_value, expected_json_value)

    else:
        converted_value = json.loads(expected_json_value)
        nose.tools.assert_equal(actual_json_value, converted_value)
コード例 #5
0
def json_object_validation(step, json_path, expected_json_value):
    response = world.response
    data = response.json()
    actual_json_value = jpath.get(json_path, data)

    if expected_json_value.startswith(WORLD_PREFIX):
        expected_json_value = getattr(world,
                                      expected_json_value[len(WORLD_PREFIX):])
    else:
        converted_value = json.loads(expected_json_value)
        actual_json_value.should.be.equal(converted_value)
コード例 #6
0
def store_parameter_with_path(context, parameter_name, json_path):
    data = context.r.json()
    parameter_value = jpath.get(json_path, data)

    print('')
    print(parameter_value)
    print('')

    setattr(context, parameter_name, parameter_value)

    print('')
    print(getattr(context, parameter_name))
    print('')
コード例 #7
0
ファイル: __init__.py プロジェクト: stanfy/behave-rest
def store_parameter_with_path(context, parameter_name, json_path):
    data = context.r.json()
    parameter_value = jpath.get(json_path, data)

    print('')
    print(parameter_value)
    print('')

    setattr(context, parameter_name, parameter_value)

    print('')
    print(getattr(context, parameter_name))
    print('')
コード例 #8
0
ファイル: __init__.py プロジェクト: velimir/behave-http
def poll_GET(context, url_path_segment, jsonpath):
    json_value = json.loads(context.data.decode('utf-8'))
    url = append_path(context.server, url_path_segment)
    for i in range(context.n_attempts):
        response = requests.get(
            url, headers=context.headers, auth=context.auth)
        if jpath.get(jsonpath, response.json()) == json_value:
            context.response = response
            return
        time.sleep(context.pause_between_attempts)
    raise AssertionError(
        'Condition not met after %d attempts' %
        context.n_attempts)  # pragma: no cover
コード例 #9
0
def make_queries(parsed_arg, json):
    '''
        apply jpath to every query in parsed args
        return list of strs
        (plain text and results of queries)
        expected generator as parsed_args
        and json to pass to jpath.
    '''
    for a in parsed_arg:
        if a.keys()[0] == 'str':
            yield a['str']
        elif a.keys()[0] == 'jpath':
            result = jpath.get(a['jpath'], json)
            # typechecking here
            yield str(result)
コード例 #10
0
ファイル: jsoniter.py プロジェクト: amarao/json4shell
def make_queries(parsed_arg, json):
    '''
        apply jpath to every query in parsed args
        return list of strs
        (plain text and results of queries)
        expected generator as parsed_args
        and json to pass to jpath.
    '''
    for a in parsed_arg:
        if a.keys()[0] == 'str':
            yield a['str']
        elif a.keys()[0] == 'jpath':
            result = jpath.get(a['jpath'], json)
            # typechecking here
            yield str(result)
コード例 #11
0
def step_impl(context, tag_key, expected_tag_value):

    response_json = context.r.json()
    if expected_tag_value.startswith("#DR#."):
        expected_tag_value = loadfile('features/testData/' +
                                      expected_tag_value[5:])

    # encoding and Decoding expected value to unicode for escape character
    my_bytes = expected_tag_value.encode("utf-8")
    decoded_message_expected_tag_value = my_bytes.decode("unicode_escape")

    # encoding and Decoding expected value to unicode for escape character
    actual_tag_value = jpath.get(tag_key, response_json)
    my_bytes_actual = actual_tag_value.encode("utf-8")
    decoded_message_actual_tag_value = my_bytes_actual.decode("unicode_escape")
    #print("Vaibhav agarwal - expected decoded---- " + decoded_message_expected_tag_value +"---VaiibhavEND")
    #print("Vaibhav agarwal actual--decodec ---- " + decoded_message_actual_tag_value +"---VaiibhavEND")

    #for removing max limit on comparision
    nose.tools.assert_equal.__self__.maxDiff = None
    nose.tools.assert_equal(decoded_message_actual_tag_value,
                            decoded_message_expected_tag_value)
コード例 #12
0
ファイル: __init__.py プロジェクト: velimir0xff/behave-http
def store_for_template(context, jsonpath, variable):
    context.template_data[variable] = jpath.get(
        jsonpath, context.response.json())
コード例 #13
0
ファイル: rest.py プロジェクト: aldefalco/webguide
def json_at_path(context, jsonpath):
    json_value = json.loads(context.data)
    assert_equal(jpath.get(jsonpath, context.response.json), json_value)
コード例 #14
0
ファイル: __init__.py プロジェクト: JoanJia/behave
def json_at_path(context, jsonpath):
    ensure(jpath.get(jsonpath, context.response.json())).equals(
        json.loads(context.data.decode('utf-8')))
コード例 #15
0
ファイル: __init__.py プロジェクト: JoanJia/behave
def json_at_path_inline(context, jsonpath, value):
    json_value = json.loads(value)
    ensure(jpath.get(jsonpath, context.response.json())).equals(json_value)
コード例 #16
0
ファイル: __init__.py プロジェクト: JoanJia/behave
def json_array_len_at_path_inline(context, jsonpath, value):
    length = int(json.loads(value))
    ensure(jpath.get(jsonpath, context.response.json())).has_length(length)
コード例 #17
0
ファイル: __init__.py プロジェクト: JoanJia/behave
def store_for_template(context, jsonpath, variable):
    context.template_data[variable] = jpath.get(jsonpath,
                                                context.response.json())
コード例 #18
0
ファイル: __init__.py プロジェクト: velimir0xff/behave-http
def json_at_path(context, jsonpath):
    ensure(jpath.get(jsonpath, context.response.json())).equals(
        json.loads(context.data.decode('utf-8')))
コード例 #19
0
ファイル: __init__.py プロジェクト: velimir0xff/behave-http
def json_at_path_inline(context, jsonpath, value):
    json_value = json.loads(value)
    ensure(jpath.get(jsonpath, context.response.json())).equals(json_value)
コード例 #20
0
ファイル: __init__.py プロジェクト: velimir0xff/behave-http
def json_array_len_at_path_inline(context, jsonpath, value):
    length = int(json.loads(value))
    ensure(jpath.get(jsonpath, context.response.json())).has_length(length)
コード例 #21
0
ファイル: rest.py プロジェクト: aldefalco/webguide
def json_at_path_inline(context, jsonpath, value):
    json_value = json.loads(value)
    assert_equal(jpath.get(jsonpath, context.response.json()), json_value)