예제 #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()