def assert_value(ctx, path, value, wrapper=None): if 'data_impl' not in ctx.zato.response: raise ValueError('Assertion called but no format set') value = wrapper(value) if wrapper else value actual = get_pointer(ctx.zato.response.data_impl, path) assert_equals(value, actual) return True
def _then_json_pointer_contains(ctx, path, expected): actual_list = get_pointer(ctx.zato.response.data_impl, path) for item in actual_list: try: assert_equals(item, expected) except AssertionError: pass else: return True else: raise AssertionError('Expected data `{}` not in `{}`'.format(expected, actual_list))
def _then_json_pointer_contains(ctx, path, expected): actual_list = get_pointer(ctx.zato.response.data_impl, path) for item in actual_list: try: assert_equals(item, expected) except AssertionError: pass else: return True else: raise AssertionError('Expected data `{}` not in `{}`'.format( expected, actual_list))
def then_store_path_under_name_with_default(ctx, path, name, default): if ctx.zato.request.is_xml: value = ctx.zato.response.data_impl.xpath(path) if value: if len(value) == 1: value = value[0].text else: value = [elem.text for elem in value] else: if default == NO_VALUE: raise ValueError('No such path `{}`'.format(path)) else: value = default else: value = get_pointer(ctx.zato.response.data_impl, path, default) if value == NO_VALUE: raise ValueError('No such path `{}`'.format(path)) ctx.zato.user_ctx[name] = value
def then_json_pointer_isnt_empty(ctx, path): actual = get_pointer(ctx.zato.response.data_impl, path, INVALID) assert actual != INVALID, 'Path `{}` Should not be empty'.format(path)
def then_json_pointer_isnt_one_of(ctx, path, value): actual = get_pointer(ctx.zato.response.data_impl, path) value = util.parse_list(value) assert actual not in value, 'Expected for `{}` ({}) not to be in `{}`'.format(actual, path, value)
def then_json_pointer_isnt_a_string(ctx, path, value): actual = get_pointer(ctx.zato.response.data_impl, path) assert actual != value, 'Expected `{}` != `{}`'.format(actual, value)
def then_json_pointer_is_a_base64_object(ctx, path, path2, value): actual = get_pointer(ctx.zato.response.data_impl, path) decoded_value = json.loads(base64.b64decode(actual)) actual = get_pointer(decoded_value, path2) return assert_equals(actual, value)
def then_json_pointer_isnt_one_of(ctx, path, value): actual = get_pointer(ctx.zato.response.data_impl, path) value = util.parse_list(value) assert actual not in value, 'Expected for `{}` ({}) not to be in `{}`'.format( actual, path, value)
def then_json_pointer_is_a_base32_crockford(ctx, path, checksum): actual = get_pointer(ctx.zato.response.data_impl, path) crockford_decode(actual.replace('-', ''), checksum.lower() == 'true')
def then_json_pointer_is_any_float(ctx, path): actual = get_pointer(ctx.zato.response.data_impl, path) assert isinstance(actual, float), \ 'Expected a float in {}, got a `{}`'.format(path, type(actual)) return True
def then_json_pointer_is_any_float(ctx, path): actual = get_pointer(ctx.zato.response.data_impl, path) assert isinstance(actual, float), "Expected a float in {}, got a `{}`".format(path, type(actual)) return True
def then_json_pointer_is_boolean_true(ctx, path): actual = get_pointer(ctx.zato.response.data_impl, path, []) assert isinstance(actual, list), 'Path `{}` should be a list'.format(path) assert actual, 'Path `{}` should not be an empty list'.format(path)
def then_json_pointer_isnt_an_empty_list(ctx, path): actual = get_pointer(ctx.zato.response.data_impl, path) assert actual != [], 'Value `{}`, is an empty list'.format(actual)
def then_json_pointer_isnt_a_string(ctx, path, value): actual = get_pointer(ctx.zato.response.data_impl, path) assert actual != value, "Expected `{}` != `{}`".format(actual, value)
def then_json_pointer_is_any_integer(ctx, path): actual = get_pointer(ctx.zato.response.data_impl, path) assert isinstance(actual, int_types), \ 'Expected an integer in {}, got a `{}`'.format(path, type(actual)) return True