Esempio n. 1
0
def test_invalid_data_for_boolean_value_type(value):
    schema = [{'id': 'test_field', 'type': 'text', 'valueType': 'boolean'}]
    schema = FormSchema(schema)
    with pytest.raises(ValidationError) as excinfo:
        schema.bind_data({'test_field': value})

    error_msg = ['Value is not a valid boolean type']
    assert error_msg == excinfo.value.messages['test_field']
Esempio n. 2
0
def test_required_validator(error_msg):
    schema = [{
        'id': 'test_field',
        'type': 'text',
        "validation": [{
            "invalidMsg": error_msg,
            "rule": "required"
        }]
    }]
    schema = FormSchema(schema)
    with pytest.raises(ValidationError) as excinfo:
        schema.bind_data({'test_field': ''})

    assert [error_msg] == excinfo.value.messages['test_field']
Esempio n. 3
0
def test_valid_error_messages_for_group_field(value, error_msg):
    schema = [{
        'id': 'test_field',
        'type': 'group',
        'multiple': True
    }, {
        'id': 'child_field',
        'parent': 'test_field',
        'type': 'text'
    }]
    schema = FormSchema(schema)
    with pytest.raises(ValidationError) as excinfo:
        schema.bind_data({'test_field': value})

    assert error_msg == excinfo.value.messages['test_field']
Esempio n. 4
0
def test_regexp_validator_shows_correct_error_message(error_msg):
    schema = [{
        'id':
        'test_field',
        'type':
        'text',
        "validation": [{
            "invalidMsg": error_msg,
            "rule": "regexp",
            "extra": {
                "regexp": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-.]+$"
            }
        }]
    }]
    schema = FormSchema(schema)
    with pytest.raises(ValidationError) as excinfo:
        schema.bind_data({'test_field': 'test_value'})

    assert [error_msg] == excinfo.value.messages['test_field']
Esempio n. 5
0
def test_invalid_data_for_text_field(value):
    schema = [{'id': 'test_field', 'type': 'text', 'valueType': 'text'}]
    schema = FormSchema(schema)
    with pytest.raises(ValidationError):
        schema.bind_data({'test_field': value})
Esempio n. 6
0
def test_valid_data_for_locale_text_value_type(value):
    schema = [{'id': 'test_field', 'type': 'text', 'valueType': 'locale_text'}]
    schema = FormSchema(schema)
    schema.bind_data({'test_field': value})
    assert schema.valuable['test_field'].value.raw_value == value
Esempio n. 7
0
def test_valid_false_data_for_boolean_value_type(value):
    schema = [{'id': 'test_field', 'type': 'text', 'valueType': 'boolean'}]
    schema = FormSchema(schema)
    schema.bind_data({'test_field': value})
    assert schema.valuable['test_field'].value.clean_value is False
def test_schema_should_accept_only_dict(data):
    schema = [{'id': 'test_field', 'type': 'text', 'valueType': 'text'}]
    schema = FormSchema(schema)
    with pytest.raises(ValidationError) as excinfo:
        schema.validate(data)
    assert excinfo.value.messages == ['Data must be a dictionary']