コード例 #1
0
def test_string_not_required():
    """If the property is not required, None is a valid value"""

    test_string = String(required=False)
    test_string.validate(None)

    assert True
コード例 #2
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_not_required():
    """If the property is not required, None is a valid value"""

    test_string = String(required=False)
    test_string.validate(None)

    assert True
コード例 #3
0
def test_string_invalid_3():
    """'foobar" is too long"""

    test_string = String(validators=[max_length(5)])

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('foobar')

    assert cm.exception.error == 'invalid'
コード例 #4
0
def test_property_required_context():
    """Test context-aware property validators"""

    test_property = String(required=lambda c: c == 'foo')

    test_property.validate(None)

    with assert_raises(InvalidPropertyError):
        test_property.validate(None, context='foo')
コード例 #5
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_invalid_1():
    """Integer is not a valid value"""

    test_string = String()

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate(5)

    assert cm.exception.error == 'invalid'
コード例 #6
0
def test_string_invalid_1():
    """Integer is not a valid value"""

    test_string = String()

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate(5)

    assert cm.exception.error == 'invalid'
コード例 #7
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_required():
    """By default, a value is required"""

    test_string = String()

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate(None)

    assert cm.exception.error == 'required'
コード例 #8
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_property_required_context():
    """Test context-aware property validators"""

    test_property = String(required=lambda c: c == 'foo')

    test_property.validate(None)

    with assert_raises(InvalidPropertyError):
        test_property.validate(None, context='foo')
コード例 #9
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_invalid_3():
    """'foobar" is too long"""

    test_string = String(validators=[max_length(5)])

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('foobar')

    assert cm.exception.error == 'invalid'
コード例 #10
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_invalid_2():
    """'fo' is too short"""

    test_string = String(validators=[min_length(3)])

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('fo')

    assert cm.exception.error == 'invalid'
コード例 #11
0
def test_string_invalid_2():
    """'fo' is too short"""

    test_string = String(validators=[min_length(3)])

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('fo')

    assert cm.exception.error == 'invalid'
コード例 #12
0
def test_string_required():
    """By default, a value is required"""

    test_string = String()

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate(None)

    assert cm.exception.error == 'required'
コード例 #13
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_choices():
    """Value can only be 'published' or 'draft'"""

    test_string = String(validators=[choices(['published', 'draft'])])

    test_string.validate('published')

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('not_a_status')

    assert cm.exception.error == 'invalid'
コード例 #14
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_regex():
    """By default, a value is required"""

    test_string = String(validators=[regex(r'^([a-z]*)$')])

    test_string.validate('abc')

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('1236580002EEEEE')

    assert cm.exception.error == 'invalid'
コード例 #15
0
def test_string_regex():
    """By default, a value is required"""

    test_string = String(validators=[regex(r'^([a-z]*)$')])

    test_string.validate('abc')

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('1236580002EEEEE')

    assert cm.exception.error == 'invalid'
コード例 #16
0
def test_string_choices():
    """Value can only be 'published' or 'draft'"""

    test_string = String(validators=[choices(['published', 'draft'])])

    test_string.validate('published')

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('not_a_status')

    assert cm.exception.error == 'invalid'
コード例 #17
0
def test_property_context():
    """Test context-aware property validators"""

    test_property = String(validators=[min_length(2, context='foo')])

    test_property.validate('a')
    test_property.validate('ab', context='foo')

    with assert_raises(InvalidPropertyError):
        test_property.validate('a', context='foo')
コード例 #18
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_property_context():
    """Test context-aware property validators"""

    test_property = String(validators=[min_length(2, context='foo')])

    test_property.validate('a')
    test_property.validate('ab', context='foo')

    with assert_raises(InvalidPropertyError):
        test_property.validate('a', context='foo')
コード例 #19
0
ファイル: test_basic.py プロジェクト: youhaveajack/kelly
def test_string_valid_1():
    """'foo' is a valid string"""
    test_string = String()
    test_string.validate('foo')

    assert True
コード例 #20
0
def test_string_valid_1():
    """'foo' is a valid string"""
    test_string = String()
    test_string.validate('foo')

    assert True