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']
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']
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']
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']
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})
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
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