示例#1
0
def test_listtype_validates_the_basics():
    list_of_strings = types.ListType(types.StringType())

    list_of_strings.validate(['list', 'of', 'strings'])
    list_of_strings.validate([])
    list_of_strings.validate(None)
    list_of_strings.validate(types.Unset)
示例#2
0
def test_stringtype_check_required():
    st = types.StringType(required=True)

    st.validate("This is a string")
    st.validate("")
    st.validate(None)
    with pytest.raises(exceptions.ValidationException):
        st.validate(types.Unset)
示例#3
0
def test_stringtype_validates_the_basics():
    st = types.StringType()
    # Accepted
    st.validate(types.Unset)
    st.validate(None)
    st.validate("This is a string")
    st.validate("")
    st.validate(1)
    st.validate(3.14)
示例#4
0
def test_listtype_item_type_is_required():
    list_of_strings = types.ListType(types.StringType(required=True))

    list_of_strings.validate(['list', 'of', 'strings'])
    list_of_strings.validate([])
    list_of_strings.validate(None)
    list_of_strings.validate(types.Unset)

    with pytest.raises(exceptions.ValidationException):
        list_of_strings.validate([types.Unset])
示例#5
0
def test_listtype_validates_max_size():
    list_of_strings = types.ListType(types.StringType(), max_length=3)

    list_of_strings.validate(['list', 'of', 'strings'])
    list_of_strings.validate([])
    list_of_strings.validate(None)
    list_of_strings.validate(types.Unset)

    with pytest.raises(exceptions.ValidationException):
        list_of_strings.validate(['li', 'st', 'of', 'strings'])
示例#6
0
def test_stringtype_max_length():
    st = types.StringType(max_length=3)

    st.validate("hi")
    st.validate("")
    st.validate(None)
    st.validate(types.Unset)

    with pytest.raises(exceptions.ValidationException):
        st.validate("hello")
示例#7
0
def test_stringtype_check_strict():
    st = types.StringType(strict=True)
    # Accepted
    st.validate(types.Unset)
    st.validate(None)
    st.validate("This is a string")
    st.validate("")
    with pytest.raises(exceptions.ValidationException):
        st.validate(1)
    with pytest.raises(exceptions.ValidationException):
        st.validate(3.14)
示例#8
0
def test_sumtype_check_required():
    st = types.SumType(types.StringType(strict=True), required=True)

    st.validate("")
    st.validate(None)

    with pytest.raises(exceptions.ValidationException):
        st.validate(types.Unset)
    with pytest.raises(exceptions.ValidationException):
        st.validate(1)
    with pytest.raises(exceptions.ValidationException):
        st.validate(3.14)
示例#9
0
def test_sumtype_validates_the_basics():
    big_strings = types.StringType(min_length=7)
    small_strings = types.StringType(max_length=3)
    big_or_small_strings = types.SumType(big_strings, small_strings)

    with pytest.raises(exceptions.ValidationException):
        big_strings.validate('li')
    with pytest.raises(exceptions.ValidationException):
        big_strings.validate('st')
    big_strings.validate('of strings')

    small_strings.validate('li')
    small_strings.validate('st')
    with pytest.raises(exceptions.ValidationException):
        small_strings.validate('of strings')

    big_or_small_strings.validate('li')
    big_or_small_strings.validate('st')
    big_or_small_strings.validate('of strings')
    big_or_small_strings.validate(None)
    big_or_small_strings.validate(types.Unset)
示例#10
0
def test_stringtype_min_length_and_required():
    st = types.StringType(min_length=3, required=True)

    st.validate("hello")

    with pytest.raises(exceptions.ValidationException):
        st.validate(None)
    with pytest.raises(exceptions.ValidationException):
        st.validate(types.Unset)
    with pytest.raises(exceptions.ValidationException):
        st.validate("")
    with pytest.raises(exceptions.ValidationException):
        st.validate("hi")
示例#11
0
def test_type_list_conversion():
    lt = types.ListType(types.StringType(min_length=5))

    lt_data = ['a', 'b', 'meow']

    assert lt.to_primitive(lt_data) == lt_data
    assert lt.to_native(lt_data) == lt_data

    lt_data = ['data', 4]

    assert lt.to_primitive(lt_data) != lt_data
    assert lt.to_primitive(lt_data)[1] == '4'
    assert lt.to_native(lt_data) != lt_data
    assert lt.to_native(lt_data)[1] == '4'
示例#12
0
 class ArtistType(types.Record):
     name = types.StringType()
     epoch = types.StringType()
     albums = types.ListType(AlbumType())
示例#13
0
 class TestType(types.Type):
     s = types.StringType()
     b = types.BooleanType()
示例#14
0
 class TestRecord(types.Record):
     s1 = types.StringType(required=True)
     s2 = types.StringType()
示例#15
0
 class TestRecord(types.Record):
     s1 = types.StringType()
示例#16
0
 class SongRecord(types.Record):
     name = types.StringType(required=True)
     author = types.StringType()
     created_at = types.DateTimeType()
示例#17
0
 class SongRecord(types.Record):
     name = types.StringType(required=True)
     author = types.StringType(required=True)
     instruments = types.ListType(types.StringType())
示例#18
0
 class TestRecord(types.Record):
     s1 = types.StringType(default='foo')
示例#19
0
 class AlbumType(types.Record):
     name = types.StringType()
     songs = types.ListType(SongType())
示例#20
0
 class Artist(types.Record):
     name = types.StringType(required=True)
     created_at = types.DateTimeType()
     website = types.URLType()
     albums = types.ListType(Album())
示例#21
0
 class Album(types.Record):
     name = types.StringType(required=True)
     created_at = types.DateTimeType()
     songs = types.ListType(Song())
示例#22
0
 class Song(types.Record):
     name = types.StringType(required=True)
     created_at = types.DateTimeType()
     file = types.UnixPathType()
     lyrics = types.StringType(max_length=255)
示例#23
0
 class MusicianRecord(types.Record):
     name = types.StringType(required=True)
示例#24
0
 class SongRecord(types.Record):
     name = types.StringType(required=True)
     author = types.StringType(required=True)
示例#25
0
 class SongType(types.Record):
     name = types.StringType(required=True)
示例#26
0
 class TestType(types.Type):
     st = types.SumType(types.StringType(min_length=10),
                        types.BooleanType())
     b = types.BooleanType()