def test_all(self): """Basic test of all properties.""" unit = Unit() unit.name = 'metre' unit.plural = 'metres' unit.abbreviation = 'm' unit.description = ( '<b>metres</b> are a metric unit of measure. There are 100 ' 'centimetres in 1 metre.'), unit.help_text = 'Help for metre unit' parameter = ResourceParameter() parameter.is_required = True parameter.minimum_allowed_value = 1.0 parameter.maximum_allowed_value = 2.0 parameter.value = 1.123 parameter.frequency = 'weekly' parameter.unit = unit self.assertEqual(1.123, parameter.value) self.assertDictEqual(unit.serialize(), parameter.unit.serialize()) self.assertEqual('weekly', parameter.frequency)
class ResourceParameter(FloatParameter): """A parameter handling specifically the resources used in InaSAFE minimum needs. :param guid: The unique reference to use when addressing this value. :type guid: str, None """ def __init__(self, guid=None): super(ResourceParameter, self).__init__(guid) self._frequency = '' self._unit = Unit() @property def frequency(self): """The frequency that the resource needs to be supplied getter. :returns: The frequency. :rtype: str """ return self._frequency @frequency.setter def frequency(self, frequency): """Set the frequency that the resource needs to be supplied. :param frequency: The frequency of the resource. :type frequency: str """ self._frequency = frequency def serialize(self): """Convert the parameter into a dictionary. :return: The parameter dictionary. :rtype: dict """ pickle = super(ResourceParameter, self).serialize() pickle['frequency'] = self.frequency pickle['unit'] = self._unit.serialize() return pickle # pylint: disable=W0221 @property def unit(self): """Property for the unit for the parameter. :returns: The unit of the parameter. :rtype: Unit """ return self._unit @unit.setter def unit(self, unit): """Setter for unit for the parameter. :param unit: Unit for parameter :type unit: Unit """ self._unit = unit