Esempio n. 1
0
def test_key_incorrect():
    error = None
    try:
        f.TypedMap(f.Bool(), f.Bool())
    except TypedClassError as exc:
        error = exc

    assert error
    msg = str(error)
    assert msg == 'key type "String" supported only'
Esempio n. 2
0
class Data(TypedClass):
    f_bool1 = f.Bool()
    f_bool2 = f.Bool()
    f_bool3_opt = f.Bool(required=False)
    f_datetime1 = f.DateTime()
    f_datetime2 = f.DateTime()
    f_decimal1 = f.Decimal()
    f_decimal2 = f.Decimal()
    f_ref1 = f.Ref(Entry)
    f_ref2 = f.Ref(Entry)
    f_ref3_list = f.List(Entry)
Esempio n. 3
0
def test_bool():
    f_bool = f.Bool()
    v_bool = True

    v_bool_simplified = f_bool.simplify(value=v_bool)

    assert v_bool_simplified == v_bool
Esempio 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
Esempio 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
Esempio 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}
Esempio n. 7
0
def test_error():
    f_bool = f.Bool()

    error = None
    try:
        validator_bool(f_bool, 1)
    except TypedClassValidationError as exc:
        error = exc

    assert error
    msg = str(error)
    assert msg == 'Not a bool'
Esempio n. 8
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'
Esempio n. 9
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()
Esempio n. 10
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)
Esempio n. 11
0
def test_ok():
    f_bool = f.Bool()

    validator_bool(f_bool, False)
    validator_bool(f_bool, True)
Esempio n. 12
0
class DataCleaned(TypedClass):
    f_bool = f.Bool()
    f_ref = f.Ref(EntryCleaned)
Esempio n. 13
0
class DataFull(TypedClass):
    f_bool = f.Bool()
    f_ref = f.Ref(EntryFull)
class Data(TypedClass):
    f_string = f.String()
    f_bool_opt = f.Bool(required=False)
Esempio n. 15
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')