Add FloatField for objects
This adds a Float field type for objects, which will be required for things like Flavor. Related to blueprint compute-manager-objects Change-Id: I260a9855721046f3af24db102a24b974bfb3518a
This commit is contained in:
parent
6a52d8eb92
commit
5533d872af
|
@ -225,6 +225,11 @@ class Integer(FieldType):
|
|||
return int(value)
|
||||
|
||||
|
||||
class Float(FieldType):
|
||||
def coerce(self, obj, attr, value):
|
||||
return float(value)
|
||||
|
||||
|
||||
class Boolean(FieldType):
|
||||
def coerce(self, obj, attr, value):
|
||||
return bool(value)
|
||||
|
@ -414,6 +419,10 @@ class IntegerField(AutoTypedField):
|
|||
AUTO_TYPE = Integer()
|
||||
|
||||
|
||||
class FloatField(AutoTypedField):
|
||||
AUTO_TYPE = Float()
|
||||
|
||||
|
||||
class BooleanField(AutoTypedField):
|
||||
AUTO_TYPE = Boolean()
|
||||
|
||||
|
|
|
@ -88,6 +88,16 @@ class TestInteger(TestField):
|
|||
self.from_primitive_values = self.coerce_good_values[0:1]
|
||||
|
||||
|
||||
class TestFloat(TestField):
|
||||
def setUp(self):
|
||||
super(TestFloat, self).setUp()
|
||||
self.field = fields.FloatField()
|
||||
self.coerce_good_values = [(1.1, 1.1), ('1.1', 1.1)]
|
||||
self.coerce_bad_values = ['foo', None]
|
||||
self.to_primitive_values = self.coerce_good_values[0:1]
|
||||
self.from_primitive_values = self.coerce_good_values[0:1]
|
||||
|
||||
|
||||
class TestBoolean(TestField):
|
||||
def setUp(self):
|
||||
super(TestField, self).setUp()
|
||||
|
|
Loading…
Reference in New Issue