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))
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)
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)
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)
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('')
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
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)
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)
def store_for_template(context, jsonpath, variable): context.template_data[variable] = jpath.get( jsonpath, context.response.json())
def json_at_path(context, jsonpath): json_value = json.loads(context.data) assert_equal(jpath.get(jsonpath, context.response.json), json_value)
def json_at_path(context, jsonpath): ensure(jpath.get(jsonpath, context.response.json())).equals( json.loads(context.data.decode('utf-8')))
def json_at_path_inline(context, jsonpath, value): json_value = json.loads(value) ensure(jpath.get(jsonpath, context.response.json())).equals(json_value)
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)
def store_for_template(context, jsonpath, variable): context.template_data[variable] = jpath.get(jsonpath, context.response.json())
def json_at_path_inline(context, jsonpath, value): json_value = json.loads(value) assert_equal(jpath.get(jsonpath, context.response.json()), json_value)