Example #1
0
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
Example #2
0
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
Example #3
0
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))
Example #4
0
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))
Example #5
0
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
Example #6
0
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
Example #7
0
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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
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)
Example #11
0
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)
Example #12
0
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')
Example #13
0
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
Example #14
0
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
Example #15
0
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)
Example #16
0
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)
Example #17
0
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)
Example #18
0
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)
Example #19
0
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)
Example #20
0
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')
Example #21
0
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)
Example #22
0
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)
Example #23
0
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