def validate_boolean(data, valid_values=None): try: converters.convert_to_boolean(data) except n_exc.InvalidInput: msg = _("'%s' is not a valid boolean value") % data LOG.debug(msg) return msg
def validate_boolean(data, valid_values=None): """Validate data is a python bool compatible object. :param data: The data to validate. :param valid_values: Not used! :return: None if the value can be converted to a bool, otherwise a human readable message indicating why data is invalid. """ try: converters.convert_to_boolean(data) except n_exc.InvalidInput: msg = _("'%s' is not a valid boolean value") % data LOG.debug(msg) return msg
def get_agents(self, context, filters=None, fields=None): agents = self._get_collection(context, Agent, self._make_agent_dict, filters=filters, fields=fields) alive = filters and filters.get('alive', None) if alive: alive = converters.convert_to_boolean(alive[0]) agents = [agent for agent in agents if agent['alive'] == alive] return agents
def get_agents(self, context, filters=None, fields=None): filters = filters or {} alive = filters and filters.pop('alive', None) agents = agent_obj.Agent.get_objects(context, **filters) if alive: alive = converters.convert_to_boolean(alive[0]) agents = [agent for agent in agents if agent.is_active == alive] return [self._make_agent_dict(agent, fields=fields) for agent in agents]
def test_convert_to_boolean_str(self): self.assertIs(converters.convert_to_boolean('True'), True) self.assertIs(converters.convert_to_boolean('true'), True) self.assertIs(converters.convert_to_boolean('False'), False) self.assertIs(converters.convert_to_boolean('false'), False) self.assertIs(converters.convert_to_boolean('0'), False) self.assertIs(converters.convert_to_boolean('1'), True) self.assertRaises(n_exc.InvalidInput, converters.convert_to_boolean, '7')
def test_convert_to_boolean_int(self): self.assertIs(converters.convert_to_boolean(0), False) self.assertIs(converters.convert_to_boolean(1), True) self.assertRaises(n_exc.InvalidInput, converters.convert_to_boolean, 7)
def test_convert_to_boolean_bool(self): self.assertIs(converters.convert_to_boolean(True), True) self.assertIs(converters.convert_to_boolean(False), False)