Added integer coercion for NumberRangeType
This commit is contained in:
@@ -8,6 +8,7 @@ Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Added JSONType
|
||||
- NumberRangeType now supports coercing of integer values
|
||||
|
||||
|
||||
0.19.0 (2013-10-24)
|
||||
|
@@ -73,8 +73,10 @@ class NumberRangeType(types.TypeDecorator, ScalarCoercible):
|
||||
if value is not None and not isinstance(value, NumberRange):
|
||||
if isinstance(value, six.string_types):
|
||||
value = NumberRange.from_normalized_str(value)
|
||||
elif isinstance(value, six.integer_types):
|
||||
value = NumberRange(value, value)
|
||||
else:
|
||||
raise TypeError
|
||||
raise TypeError('Could not coerce value to NumberRange.')
|
||||
return value
|
||||
|
||||
|
||||
|
@@ -48,11 +48,16 @@ class TestNumberRangeType(TestCase):
|
||||
building = self.session.query(self.Building).first()
|
||||
assert building.persons_at_night is None
|
||||
|
||||
def test_scalar_attributes_get_coerced_to_objects(self):
|
||||
def test_string_coercion(self):
|
||||
building = self.Building(persons_at_night='[12, 18]')
|
||||
|
||||
assert isinstance(building.persons_at_night, NumberRange)
|
||||
|
||||
def test_integer_coercion(self):
|
||||
building = self.Building(persons_at_night=15)
|
||||
assert building.persons_at_night.min_value == 15
|
||||
assert building.persons_at_night.max_value == 15
|
||||
|
||||
|
||||
class TestNumberRange(object):
|
||||
def test_equality_operator(self):
|
||||
|
Reference in New Issue
Block a user