Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 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'])
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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'
Exemplo n.º 12
0
 class ArtistType(types.Record):
     name = types.StringType()
     epoch = types.StringType()
     albums = types.ListType(AlbumType())
Exemplo n.º 13
0
 class TestType(types.Type):
     s = types.StringType()
     b = types.BooleanType()
Exemplo n.º 14
0
 class TestRecord(types.Record):
     s1 = types.StringType(required=True)
     s2 = types.StringType()
Exemplo n.º 15
0
 class TestRecord(types.Record):
     s1 = types.StringType()
Exemplo n.º 16
0
 class SongRecord(types.Record):
     name = types.StringType(required=True)
     author = types.StringType()
     created_at = types.DateTimeType()
Exemplo n.º 17
0
 class SongRecord(types.Record):
     name = types.StringType(required=True)
     author = types.StringType(required=True)
     instruments = types.ListType(types.StringType())
Exemplo n.º 18
0
 class TestRecord(types.Record):
     s1 = types.StringType(default='foo')
Exemplo n.º 19
0
 class AlbumType(types.Record):
     name = types.StringType()
     songs = types.ListType(SongType())
Exemplo n.º 20
0
 class Artist(types.Record):
     name = types.StringType(required=True)
     created_at = types.DateTimeType()
     website = types.URLType()
     albums = types.ListType(Album())
Exemplo n.º 21
0
 class Album(types.Record):
     name = types.StringType(required=True)
     created_at = types.DateTimeType()
     songs = types.ListType(Song())
Exemplo n.º 22
0
 class Song(types.Record):
     name = types.StringType(required=True)
     created_at = types.DateTimeType()
     file = types.UnixPathType()
     lyrics = types.StringType(max_length=255)
Exemplo n.º 23
0
 class MusicianRecord(types.Record):
     name = types.StringType(required=True)
Exemplo n.º 24
0
 class SongRecord(types.Record):
     name = types.StringType(required=True)
     author = types.StringType(required=True)
Exemplo n.º 25
0
 class SongType(types.Record):
     name = types.StringType(required=True)
Exemplo n.º 26
0
 class TestType(types.Type):
     st = types.SumType(types.StringType(min_length=10),
                        types.BooleanType())
     b = types.BooleanType()