Exemplo n.º 1
0
def test_validate_data_against_json_schema():
    func = decorators.validate_data_against_json_schema(lambda data: data)
    data = {
        'name': 'TEST: List all users',
        'verb': 'GET',
        'endpoint': 'users',
        'host': 'https://localhost.com',
    }
    func_result = func(data)

    assert id(func_result) == id(data)
Exemplo n.º 2
0
def test_validate_data_against_json_schema():
    func = decorators.validate_data_against_json_schema(lambda data: data)
    data = {
        "name": "TEST: List all users",
        "verb": "GET",
        "endpoint": "users",
        "host": "https://localhost.com",
    }
    func_result = func(data)

    assert id(func_result) == id(data)
Exemplo n.º 3
0
def test_validate_data_against_json_schema_with_not_supported_argument_type():
    with pytest.raises(TypeError) as exc:
        func = decorators.validate_data_against_json_schema(lambda data: data)
        data = {
            'TEST: List all users',
            'GET',
            'users',
            'https://localhost.com',
        }
        func(data)

    part_of_exc_msg = 'Not a type of {type}'.format(type=type(data))

    assert part_of_exc_msg in str(exc.value)
Exemplo n.º 4
0
def test_validate_data_against_json_schema_with_not_supported_http_method():
    with pytest.raises(HTTPMethodNotSupportedError) as exc:
        func = decorators.validate_data_against_json_schema(lambda data: data)
        data = {
            'name': 'TEST: List all users',
            'verb': 'HEAD',
            'endpoint': 'users',
            'host': 'https://localhost.com',
        }
        func(data)

    part_of_exc_msg = "An HTTP method ('{http_method}') is not".format(
        http_method=data['verb'])

    assert part_of_exc_msg in str(exc.value)
Exemplo n.º 5
0
def test_validate_data_against_json_schema_with_invalid_value_type_in_data():
    with pytest.raises(ValidationError) as exc:
        func = decorators.validate_data_against_json_schema(lambda data: data)
        data = {
            'name': 'TEST: List all users',
            'verb': 'GET',
            'endpoint': 'users',
            'host': 'https://localhost.com',
            'response': True,
        }
        func(data)

    part_of_exc_msg = ("{value} is not of type 'object'".format(
        value=data['response']))

    assert part_of_exc_msg in str(exc.value)