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)
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)
def test_not_decimal(): f_decimal = f.Decimal() error = None try: validator_decimal(f_decimal, 1) except TypedClassValidationError as exc: error = exc assert error msg = str(error) assert msg == 'Not a Decimal'
def test_max_incorrect(): f_decimal = f.Decimal(max_value=Decimal('0.01')) error = None try: validator_decimal(f_decimal, Decimal('0.0101')) except TypedClassValidationError as exc: error = exc assert error msg = str(error) assert msg == 'Decimal value > 0.01'
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()
def test_decimal(): f_decimal = f.Decimal() v_decimal = Decimal('0.1234567890') v_decimal_simplified_ok = '0.1234567890' m_simplifier = Mock(return_value=v_decimal_simplified_ok) f_decimal.simplifier = m_simplifier v_decimal_simplified = f_decimal.simplify(value=v_decimal) assert m_simplifier.call_args_list == [ call(v_decimal), ] assert v_decimal_simplified == v_decimal_simplified_ok
class Data(TypedClass): int = f.Int() int_list = f.List(f.Int) float = f.Float() float_list = f.List(f.Float) decimal = f.Decimal() decimal_list = f.List(f.Decimal) dt = f.DateTime() dt_list = f.List(f.DateTime) date = f.Date() date_list = f.List(f.Date) time = f.Time() time_list = f.List(f.Time) entry_ref = f.Ref(Entry) entry_list = f.List(Entry) rawmap = f.RawMap() rawlist = f.RawList()
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')
def test_ok(): f_decimal = f.Decimal(min_value=Decimal('0.01'), max_value=Decimal('0.01')) validator_decimal(f_decimal, Decimal('0.01'))