How to use the fastjsonschema.JsonSchemaException function in fastjsonschema

To help you get started, we’ve selected a few fastjsonschema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github horejsek / python-fastjsonschema / tests / test_object.py View on Github external
    ({'a': 1, 'b': 2}, JsonSchemaException('data must contain less than or equal to 1 properties', value='{data}', name='data', definition='{definition}', rule='maxProperties')),
])
def test_max_properties(asserter, value, expected):
    asserter({
        'type': 'object',
        'maxProperties': 1,
    }, value, expected)
github horejsek / python-fastjsonschema / tests / test_object.py View on Github external
    ({'a': 1, 'b': 2}, JsonSchemaException('data.b must be string', value=2, name='data.b', definition={'type': 'string'}, rule='type')),
    ({'a': 1, 'b': '', 'additional': ''}, {'a': 1, 'b': '', 'additional': ''}),
    ({'a': 1, 'b': '', 'any': True}, JsonSchemaException('data.any must be string', value=True, name='data.any', definition={'type': 'string'}, rule='type')),
])
def test_properties_with_additional_properties(asserter, value, expected):
    asserter({
        'type': 'object',
        'properties': {
            'a': {'type': 'number'},
            'b': {'type': 'string'},
        },
        'additionalProperties': {'type': 'string'},
    }, value, expected)
github horejsek / python-fastjsonschema / tests / test_array.py View on Github external
exc = JsonSchemaException('data must be array', value='{data}', name='data', definition='{definition}', rule='type')
@pytest.mark.parametrize('value, expected', [
    (0, exc),
    (None, exc),
    (True, exc),
    (False, exc),
    ('abc', exc),
    ([], []),
    ([1, 'a', True], [1, 'a', True]),
    ({}, exc),
])
def test_array(asserter, value, expected):
    asserter({'type': 'array'}, value, expected)


exc = JsonSchemaException('data must contain less than or equal to 1 items', value='{data}', name='data', definition='{definition}', rule='maxItems')
@pytest.mark.parametrize('value, expected', [
    ([], []),
    ([1], [1]),
    ([1, 1], exc),
    ([1, 2, 3], exc),
])
def test_max_items(asserter, value, expected):
    asserter({
        'type': 'array',
        'maxItems': 1,
    }, value, expected)


exc = JsonSchemaException('data must contain at least 2 items', value='{data}', name='data', definition='{definition}', rule='minItems')
@pytest.mark.parametrize('value, expected', [
    ([], exc),
github horejsek / python-fastjsonschema / tests / test_array.py View on Github external
    ([1, 'a', 2], JsonSchemaException('data must contain only specified items', value='{data}', name='data', definition='{definition}', rule='items')),
    ([1, 'a', 'b'], JsonSchemaException('data must contain only specified items', value='{data}', name='data', definition='{definition}', rule='items')),
])
def test_different_items_without_additional_items(asserter, value, expected):
    asserter({
        'type': 'array',
        'items': [
            {'type': 'number'},
            {'type': 'string'},
        ],
        'additionalItems': False,
    }, value, expected)
github horejsek / python-fastjsonschema / tests / test_number.py View on Github external
exc = JsonSchemaException('data must be bigger than or equal to 10', value='{data}', name='data', definition='{definition}', rule='minimum')
@pytest.mark.parametrize('value, expected', [
    (-5, exc),
    (9, exc),
    (10, 10),
    (11, 11),
    (20, 20),
])
def test_minimum(asserter, number_type, value, expected):
    asserter({
        'type': number_type,
        'minimum': 10,
    }, value, expected)


exc = JsonSchemaException('data must be bigger than 10', value='{data}', name='data', definition='{definition}', rule='minimum')
@pytest.mark.parametrize('value, expected', [
    (-5, exc),
    (9, exc),
    (10, exc),
    (11, 11),
    (20, 20),
])
def test_exclusive_minimum(asserter, number_type, value, expected):
    asserter({
        'type': number_type,
        'minimum': 10,
        'exclusiveMinimum': True,
    }, value, expected)


exc = JsonSchemaException('data must be multiple of 3', value='{data}', name='data', definition='{definition}', rule='multipleOf')
github horejsek / python-fastjsonschema / tests / test_number.py View on Github external
(-5, -5),
    (0, 0),
    (5, 5),
    (None, exc),
    (True, exc),
    ('abc', exc),
    ([], exc),
    ({}, exc),
])
def test_number(asserter, number_type, value, expected):
    if isinstance(expected, JsonSchemaException):
        expected = JsonSchemaException(expected.message.format(number_type=number_type), value='{data}', name='data', definition='{definition}', rule='type')
    asserter({'type': number_type}, value, expected)


exc = JsonSchemaException('data must be smaller than or equal to 10', value='{data}', name='data', definition='{definition}', rule='maximum')
@pytest.mark.parametrize('value, expected', [
    (-5, -5),
    (5, 5),
    (9, 9),
    (10, 10),
    (11, exc),
    (20, exc),
])
def test_maximum(asserter, number_type, value, expected):
    asserter({
        'type': number_type,
        'maximum': 10,
    }, value, expected)


exc = JsonSchemaException('data must be smaller than 10', value='{data}', name='data', definition='{definition}', rule='maximum')
github horejsek / python-fastjsonschema / tests / test_number.py View on Github external
def test_number(asserter, number_type, value, expected):
    if isinstance(expected, JsonSchemaException):
        expected = JsonSchemaException(expected.message.format(number_type=number_type), value='{data}', name='data', definition='{definition}', rule='type')
    asserter({'type': number_type}, value, expected)
github horejsek / python-fastjsonschema / tests / test_integration.py View on Github external
        JsonSchemaException('data[0] must be smaller than 10', value=10, name='data[0]', definition=definition['items'][0], rule='maximum'),
    ),
    (
        [9, 'xxx', [1], {'a': 'a', 'b': 'b', 'c': 'xy'}, 'str', 5],
        JsonSchemaException('data[1] must be one of [\'hello\', \'world\']', value='xxx', name='data[1]', definition=definition['items'][1], rule='enum'),
    ),
    (
        [9, 'hello', [], {'a': 'a', 'b': 'b', 'c': 'xy'}, 'str', 5],
        JsonSchemaException('data[2] must contain at least 1 items', value=[], name='data[2]', definition=definition['items'][2], rule='minItems'),
    ),
    (
        [9, 'hello', [1, 2, 3], {'a': 'a', 'b': 'b', 'c': 'xy'}, 'str', 5],
        JsonSchemaException('data[2][1] must be string', value=2, name='data[2][1]', definition={'type': 'string'}, rule='type'),
    ),
    (
        [9, 'hello', [1], {'a': 'a', 'x': 'x', 'y': 'y'}, 'str', 5],
        JsonSchemaException('data[3] must contain [\'a\', \'b\'] properties', value={'a': 'a', 'x': 'x', 'y': 'y'}, name='data[3]', definition=definition['items'][3], rule='required'),
github polyswarm / polyswarmd / src / polyswarmd / views / v0 / staking.py View on Github external
def post_arbiter_staking_deposit():
    account = g.chain.w3.toChecksumAddress(g.eth_address)
    base_nonce = int(request.args.get('base_nonce', g.chain.w3.eth.getTransactionCount(account)))

    body = request.get_json()
    try:
        _post_arbiter_staking_deposit_schema(body)
    except fastjsonschema.JsonSchemaException as e:
        return failure('Invalid JSON: ' + e.message, 400)

    amount = int(body['amount'])

    total = g.chain.arbiter_staking.contract.functions.balanceOf(account).call()

    if amount + total >= eth.staking_total_max(g.chain.arbiter_staking.contract):
        return failure('Total stake above allowable maximum.', 400)

    transactions = [
        build_transaction(
            g.chain.nectar_token.contract.functions.approve(
                g.chain.arbiter_staking.contract.address, amount
            ), base_nonce
        ),
        build_transaction(
github dragonchain / dragonchain / dragonchain / webserver / routes / interchain.py View on Github external
def create_ethereum_interchain_v1(**kwargs) -> Tuple[str, int, Dict[str, str]]:
    if not flask.request.is_json:
        raise exceptions.BadRequest("Could not parse JSON")
    data = flask.request.json
    try:
        _validate_ethereum_network_create_v1(data)
    except fastjsonschema.JsonSchemaException as e:
        raise exceptions.ValidationException(str(e))

    return helpers.flask_http_response(201, interchain.create_ethereum_interchain_v1(data))