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)
def test_datetime_empty(): f_datetime = f.DateTime(required=False) m_simplifier = Mock() f_datetime.simplifier = m_simplifier v_datetime_simplified = f_datetime.simplify(value=None) assert m_simplifier.called is False assert v_datetime_simplified is None
def test_error(): f_datetime = f.DateTime() error = None try: validator_datetime(f_datetime, 1) except TypedClassValidationError as exc: error = exc assert error msg = str(error) assert msg == 'Not a datetime'
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_datetime(): f_datetime = f.DateTime() v_datetime = dt.datetime(2017, 4, 20, 18, 50, 13, 36574) v_datetime_simplified_ok = '2017-04-20T18:50:13:036574' m_simplifier = Mock(return_value=v_datetime_simplified_ok) f_datetime.simplifier = m_simplifier v_datetime_simplified = f_datetime.simplify(value=v_datetime) assert m_simplifier.call_args_list == [ call(v_datetime), ] assert v_datetime_simplified == v_datetime_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()
def test_ok(): f_datetime = f.DateTime() validator_datetime(f_datetime, dt.datetime.now())
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')