Exemplo n.º 1
0
class DataCleaned2(DataCleaned1):
    __ignored_fields__ = (
        'sensitive_data2',
        'sensitive_data3',
    )
    sensitive_data3 = f.String(required=False)
    string4 = f.String(required=False)
Exemplo n.º 2
0
class Data(TypedClass):
    f_bool = f.Bool()
    f_datetime = f.DateTime()
    f_date = f.Date()
    f_decimal = f.Decimal()
    f_int = f.Int()
    f_float = f.Float()
    f_string = f.String()
    f_list = f.List(f.String)
    f_ref = f.Ref(Entry)
    f_typedmap = f.TypedMap(key=f.String(), value=f.String())
    f_rawmap = f.RawMap()
    f_rawlist = f.RawList()
    f_time = f.Time()
Exemplo n.º 3
0
def test_string():
    f_string = f.String()
    v_string = 'abc'

    v_string_simplified = f_string.simplify(value=v_string)

    assert v_string_simplified == v_string
Exemplo n.º 4
0
def test_ok():
    f_typedmap = f.TypedMap(f.String(), f.Bool())
    v_typedmap_ok = {'a': False, 'b': True}

    v_typedmap = f_typedmap.simplify(value=v_typedmap_ok)

    assert v_typedmap == v_typedmap_ok
Exemplo n.º 5
0
def test_empty_ok():
    f_typedmap = f.TypedMap(f.String(), f.Bool(), required=False)
    v_raw_map_ok = None

    v_typedmap = f_typedmap.process(name='f_typedmap', value=v_raw_map_ok)

    assert v_typedmap == v_raw_map_ok
Exemplo n.º 6
0
def test_ok():
    f_typedmap = f.TypedMap(f.String(), f.Bool())

    v_typedmap = f_typedmap.process(name='f_typedmap',
                                    value={
                                        'a': '0',
                                        'b': True
                                    })

    assert v_typedmap == {'a': False, 'b': True}
Exemplo n.º 7
0
class TypedClassHTMLFieldProperties(TypedClass):
    # base:
    required = f.Bool()
    comment = f.String(required=False)

    # digital only:
    min_value = f.Decimal(required=False)
    max_value = f.Decimal(required=False)

    # string only:
    min_length = f.Int(required=False)
    max_length = f.Int(required=False)
    choices = f.List(f.String, required=False)

    # typedmap only:
    key = f.String(min_length=1, required=False)
    value = f.String(min_length=1, required=False)

    # special only:
    cls_name = f.String(min_length=1, required=False)
Exemplo n.º 8
0
def test_not_string():
    f_string = f.String()

    error = None
    try:
        validator_string(f_string, 1)
    except TypedClassValidationError as exc:
        error = exc

    assert error
    msg = str(error)
    assert msg == 'Not a string'
Exemplo n.º 9
0
def test_choices_incorrect():
    f_string = f.String(choices=('a', 'b'))

    error = None
    try:
        validator_string(f_string, 'c')
    except TypedClassValidationError as exc:
        error = exc

    assert error
    msg = str(error)
    assert msg == 'value not found in choices'
Exemplo n.º 10
0
def test_max_incorrect():
    f_string = f.String(max_length=1)

    error = None
    try:
        validator_string(f_string, 'ab')
    except TypedClassValidationError as exc:
        error = exc

    assert error
    msg = str(error)
    assert msg == 'String length > 1'
Exemplo n.º 11
0
def test_error():
    f_typedmap = f.TypedMap(f.String(), f.Bool())

    error = None
    try:
        f_typedmap.process(name='f_typedmap', value=123)
    except TypedClassValidationError as exc:
        error = exc

    assert error
    msg = str(error)
    assert msg == 'f_typedmap is not Mapping type'
Exemplo n.º 12
0
class EntryFull(TypedClass):
    f_string_internal = f.String()
    f_string_public = f.String()
    f_items = f.List(ItemFull)
Exemplo n.º 13
0
class Entry1(TypedClass):
    f_string1 = f.String()
    f_entry2_ref = f.List(Entry2)
Exemplo n.º 14
0
class TypedClassHTMLField(TypedClass):
    name = f.String(min_length=1)
    ftype = f.String(min_length=1)
    properties = f.Ref(TypedClassHTMLFieldProperties)
Exemplo n.º 15
0
class Entry(TypedClass):
    name = f.String()
    age = f.Int()
Exemplo n.º 16
0
class Data(TypedClass):
    # base:
    f_bool1 = f.Bool(required=True)
    f_bool2 = f.Bool(required=False, comment='test f_bool2')
    f_bool3 = f.Bool(extra_validators=(_extra_validator, ))

    f_date1 = f.Date(required=True)
    f_date2 = f.Date(required=False, comment='test f_date2')

    f_datetime1 = f.DateTime(required=True)
    f_datetime2 = f.DateTime(required=False, comment='test f_datetime2')

    f_decimal1 = f.Decimal(required=True)
    f_decimal2 = f.Decimal(required=False, comment='test f_decimal2')
    f_decimal3 = f.Decimal(min_value=Decimal('0.0001'),
                           max_value=Decimal('1.234567890'))

    f_int1 = f.Int(required=True)
    f_int2 = f.Int(required=False, comment='test f_int2')
    f_int3 = f.Int(min_value=-999, max_value=999)

    f_float1 = f.Float(required=True)
    f_float2 = f.Float(required=False, comment='test f_float2')
    f_float3 = f.Float(min_value=1.23, max_value=4.56)

    f_string1 = f.String(required=True)
    f_string2 = f.String(required=False, comment='test f_string2')
    f_string3 = f.String(min_length=1, max_length=50, choices=(
        'a',
        'b',
    ))
    f_string4 = f.String(choices=())

    f_time1 = f.Time(required=True)
    f_time2 = f.Time(required=False, comment='test f_time2')

    # special:
    f_list1 = f.List(f.String, required=True)
    f_list2 = f.List(f.String, required=False, comment='test f_list2')
    f_list3 = f.List(Entry1)

    f_ref1 = f.Ref(Entry1, required=True)
    f_ref2 = f.Ref(Entry1, required=False, comment='test f_ref2')

    f_set1 = f.Set(f.String, required=True)
    f_set2 = f.Set(f.String, required=False, comment='test f_set2')
    f_set3 = f.Set(Entry1)

    # map-like:
    f_rawmap1 = f.RawMap(required=True)
    f_rawmap2 = f.RawMap(required=False, comment='test f_rawmap2')

    f_typedmap1 = f.TypedMap(key=f.String(), value=f.String(), required=True)
    f_typedmap2 = f.TypedMap(key=f.String(),
                             value=f.String(),
                             required=False,
                             comment='test f_typedmap2')

    # list-like:
    f_rawlist1 = f.RawList(required=True)
    f_rawlist2 = f.RawList(required=False, comment='test f_rawlist2')
Exemplo n.º 17
0
def test_ok_list():
    f_string = f.String(min_length=1, max_length=1, choices=['a', 'b'])
    validator_string(f_string, 'a')
Exemplo n.º 18
0
class TypedClassHTMLEntry(TypedClass):
    class_name = f.String(min_length=1)
    fields = f.List(TypedClassHTMLField)
Exemplo n.º 19
0
def test_ok_tuple():
    f_string = f.String(min_length=1, max_length=1, choices=('a', 'b'))
    validator_string(f_string, 'a')
Exemplo n.º 20
0
class Data(TypedClass):
    f_string = f.String()
    f_bool_opt = f.Bool(required=False)
Exemplo n.º 21
0
class DataCleaned1(Data):
    __ignored_fields__ = (
        'sensitive_data1',
    )
    string3 = f.String(required=False)
Exemplo n.º 22
0
class Entry(TypedClass):
    f_string = f.String()
Exemplo n.º 23
0
class Data(TypedClass):
    string1 = f.String()
    string2 = f.String()
    sensitive_data1 = f.String()
    sensitive_data2 = f.String()
Exemplo n.º 24
0
class Data(TypedClass):
    string1 = f.String()
    string2 = f.String()
Exemplo n.º 25
0
class ItemCleaned(TypedClass):
    a = f.String()
Exemplo n.º 26
0
class Entry3(TypedClass):
    f_string3 = f.String()
Exemplo n.º 27
0
class EntryCleaned(TypedClass):
    f_string_public = f.String()
    f_items = f.List(ItemCleaned)
Exemplo n.º 28
0
class ItemFull(TypedClass):
    a = f.String()
    b = f.String()
Exemplo n.º 29
0
class Entry(TypedClass):
    test = f.String()
Exemplo n.º 30
0
class Entry2(TypedClass):
    f_string2 = f.String()
    f_entry3_ref = f.List(Entry3)