How to use the jsonmodels.validators.Regex function in jsonmodels

To help you get started, we’ve selected a few jsonmodels 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 jazzband / jsonmodels / tests / test_validation.py View on Github external
def test_regex_validation_flags():
    # Invalid flags ignored
    validator = validators.Regex("foo", bla=True, ble=False, ignorecase=True)
    assert validator.flags == [validators.Regex.FLAGS["ignorecase"]]

    # Flag kwargs must be True-y
    validator = validators.Regex("foo", ignorecase=False, multiline=True)
    assert validator.flags == [validators.Regex.FLAGS["multiline"]]

    # ECMA pattern flags recognized
    validator = validators.Regex("/foo/im")
    assert sorted(validator.flags) == sorted([
        validators.Regex.FLAGS["multiline"],
        validators.Regex.FLAGS["ignorecase"],
    ])

    # ECMA pattern overrides flags kwargs
    validator = validators.Regex("/foo/", ignorecase=True, multiline=True)
    assert validator.flags == []
github jazzband / jsonmodels / tests / test_validation.py View on Github external
def test_regex_validation_flags():
    # Invalid flags ignored
    validator = validators.Regex("foo", bla=True, ble=False, ignorecase=True)
    assert validator.flags == [validators.Regex.FLAGS["ignorecase"]]

    # Flag kwargs must be True-y
    validator = validators.Regex("foo", ignorecase=False, multiline=True)
    assert validator.flags == [validators.Regex.FLAGS["multiline"]]

    # ECMA pattern flags recognized
    validator = validators.Regex("/foo/im")
    assert sorted(validator.flags) == sorted([
        validators.Regex.FLAGS["multiline"],
        validators.Regex.FLAGS["ignorecase"],
    ])

    # ECMA pattern overrides flags kwargs
    validator = validators.Regex("/foo/", ignorecase=True, multiline=True)
    assert validator.flags == []
github jazzband / jsonmodels / tests / test_schema.py View on Github external
def test_regex_validator_when_ecma_regex_given(self):

        class Person(models.Base):

            name = fields.StringField(
                validators=validators.Regex('/^some pattern$/'))

        schema = Person.to_json_schema()

        pattern = get_fixture('schema_pattern.json')
        self.assertTrue(compare_schemas(pattern, schema))
github jazzband / jsonmodels / tests / test_validation.py View on Github external
validator = validators.Regex("foo", bla=True, ble=False, ignorecase=True)
    assert validator.flags == [validators.Regex.FLAGS["ignorecase"]]

    # Flag kwargs must be True-y
    validator = validators.Regex("foo", ignorecase=False, multiline=True)
    assert validator.flags == [validators.Regex.FLAGS["multiline"]]

    # ECMA pattern flags recognized
    validator = validators.Regex("/foo/im")
    assert sorted(validator.flags) == sorted([
        validators.Regex.FLAGS["multiline"],
        validators.Regex.FLAGS["ignorecase"],
    ])

    # ECMA pattern overrides flags kwargs
    validator = validators.Regex("/foo/", ignorecase=True, multiline=True)
    assert validator.flags == []
github jazzband / jsonmodels / tests / test_schema.py View on Github external
def test_regex_validator(self):

        class Person(models.Base):

            name = fields.StringField(
                validators=validators.Regex('^some pattern$'))

        schema = Person.to_json_schema()

        pattern = get_fixture('schema_pattern.json')
        self.assertTrue(compare_schemas(pattern, schema))
github jazzband / jsonmodels / tests / test_schema.py View on Github external
def test_regex_validator_with_flag(self):

        class Person(models.Base):

            name = fields.StringField(
                validators=validators.Regex(
                    '^some pattern$', ignorecase=True))

        schema = Person.to_json_schema()

        pattern = get_fixture('schema_pattern_flag.json')
        self.assertTrue(compare_schemas(pattern, schema))
github jazzband / jsonmodels / tests / test_validation.py View on Github external
def test_regex_validator():

    class Person(models.Base):

        name = fields.StringField(
            validators=validators.Regex('^[a-z]+$', ignorecase=True))

    person = Person()

    with pytest.raises(errors.ValidationError):
        person.name = '123'

    person.name = 'Jimmy'
github jazzband / jsonmodels / tests / test_validation.py View on Github external
def test_regex_validator_when_ecma_regex_given():

    class Person(models.Base):

        name = fields.StringField(
            validators=validators.Regex('/^[a-z]+$/i', ignorecase=False))

    person = Person()

    with pytest.raises(errors.ValidationError):
        person.name = '123'

    person.name = 'Jimmy'
github jazzband / jsonmodels / tests / test_validation.py View on Github external
def test_regex_validation_flags():
    # Invalid flags ignored
    validator = validators.Regex("foo", bla=True, ble=False, ignorecase=True)
    assert validator.flags == [validators.Regex.FLAGS["ignorecase"]]

    # Flag kwargs must be True-y
    validator = validators.Regex("foo", ignorecase=False, multiline=True)
    assert validator.flags == [validators.Regex.FLAGS["multiline"]]

    # ECMA pattern flags recognized
    validator = validators.Regex("/foo/im")
    assert sorted(validator.flags) == sorted([
        validators.Regex.FLAGS["multiline"],
        validators.Regex.FLAGS["ignorecase"],
    ])

    # ECMA pattern overrides flags kwargs
    validator = validators.Regex("/foo/", ignorecase=True, multiline=True)
    assert validator.flags == []