def test_decimal_field_invalid_type(): field = Decimal(name='name') mapper_session = get_mapper_session( data={'name': None, 'email': '*****@*****.**'}, output={}) with pytest.raises(FieldInvalid): field.marshal(mapper_session)
def test_decimal_field_invalid_type(): field = Decimal(name='name') mapper_session = get_mapper_session( data={'name': None, 'email': '*****@*****.**'}, output={}) with pytest.raises(FieldInvalid): field.marshal(mapper_session)
def test_decimal_input_precision(): field = Decimal(name='name', required=True, precision=4) output = {} mapper_session = get_mapper_session( data={'name': '3.147261', 'email': '*****@*****.**'}, output=output) field.marshal(mapper_session) assert output == {'name': decimal.Decimal('3.1473')}
def test_decimal_input_bounds_when_passed_as_string(): field = Decimal(name='name', required=True, min=0.1) output = {} mapper_session = get_mapper_session( data={'name': "2", 'email': '*****@*****.**'}, output=output) field.marshal(mapper_session) assert output == {'name': decimal.Decimal(2)}
def test_decimal_input_precision(): field = Decimal(name='name', required=True, precision=4) output = {} mapper_session = get_mapper_session( data={'name': '3.147261', 'email': '*****@*****.**'}, output=output) field.marshal(mapper_session) assert output == {'name': decimal.Decimal('3.1473')}
def test_decimal_input(): field = Decimal(name='name', required=True) mapper_session = get_mapper_session(data={'email': '*****@*****.**'}, output={}) with pytest.raises(FieldInvalid): field.marshal(mapper_session) mapper_session = get_mapper_session(data={ 'name': 'foo', 'email': '*****@*****.**' }, output={}) with pytest.raises(FieldInvalid): field.marshal(mapper_session) output = {} mapper_session = get_mapper_session(data={ 'name': 2, 'email': '*****@*****.**' }, output=output) field.marshal(mapper_session) assert output == {'name': decimal.Decimal(2)}
def test_min_max_decimal(): field = Decimal(name='age', min=0, max=1.5) output = {} mapper_session = get_mapper_session(data={'age': -1}, output=output) with pytest.raises(FieldInvalid): field.marshal(mapper_session) mapper_session = get_mapper_session(data={'age': 4}, output=output) with pytest.raises(FieldInvalid): field.marshal(mapper_session) mapper_session = get_mapper_session(data={'age': 0.7}, output=output) field.marshal(mapper_session) assert output == {'age': decimal.Decimal('0.7')} mapper_session = get_mapper_session(data={'age': 1.5}, output=output) field.marshal(mapper_session) assert output == {'age': decimal.Decimal('1.5')}
def test_min_max_decimal(): field = Decimal(name='age', min=0, max=1.5) output = {} mapper_session = get_mapper_session(data={'age': -1}, output=output) with pytest.raises(FieldInvalid): field.marshal(mapper_session) mapper_session = get_mapper_session(data={'age': 4}, output=output) with pytest.raises(FieldInvalid): field.marshal(mapper_session) mapper_session = get_mapper_session(data={'age': 0.7}, output=output) field.marshal(mapper_session) assert output == {'age': decimal.Decimal('0.7')} mapper_session = get_mapper_session(data={'age': 1.5}, output=output) field.marshal(mapper_session) assert output == {'age': decimal.Decimal('1.5')}
def test_decimal_input(): field = Decimal(name='name', required=True) mapper_session = get_mapper_session( data={'email': '*****@*****.**'}, output={}) with pytest.raises(FieldInvalid): field.marshal(mapper_session) mapper_session = get_mapper_session( data={'name': 'foo', 'email': '*****@*****.**'}, output={}) with pytest.raises(FieldInvalid): field.marshal(mapper_session) output = {} mapper_session = get_mapper_session( data={'name': 2, 'email': '*****@*****.**'}, output=output) field.marshal(mapper_session) assert output == {'name': decimal.Decimal(2)}