def create(self, **kwargs): # All of the options will be present, even if the user didn't specify # them. Their values will be None, which the yum importer is set up # to handle. # Gather data repo_id = kwargs.pop('repo-id') description = kwargs.pop('description', None) display_name = kwargs.pop('display-name', None) auto_publish = kwargs.pop('auto-publish', None) if auto_publish: auto_publish = arg_to_bool(auto_publish) if auto_publish: self.context.prompt.render_failure_message(_('Value for auto-publish must be either true or false')) return try: notes = None if 'note' in kwargs and kwargs['note'] is not None: notes = args_to_notes_dict(kwargs['note'], include_none=False) importer_config = args_to_importer_config(kwargs) distributor_config = args_to_distributor_config(kwargs) except InvalidConfig, e: self.context.prompt.render_failure_message(e[0]) return
def test_false(self): # Setup test_list = [' false ', ' FALSE', 'False '] # Test that all the test list values are evaluated to False for item in test_list: self.assertFalse(arg_utils.arg_to_bool(item))
def test_invalid_bool(self): # Setup test_list = ['f', 't', 'potato'] # Test that values that are neither true nor false return None for item in test_list: self.assertTrue(arg_utils.arg_to_bool(item) is None)
def test_true(self): # Setup test_list = [' true ', ' TRUE', 'True '] # Test that all the test list values are evaluated to True for item in test_list: self.assertTrue(arg_utils.arg_to_bool(item))
def parse_boolean(value): """ Returns the boolean representation of the given user input, raising the appropriate exception if the user input cannot be parsed. :param value: user entered text extracted by the framework :type value: str :rtype: bool """ converted = arg_utils.arg_to_bool(value) if converted is None: raise ValueError(_('invalid boolean value')) else: return converted
def update(self, **kwargs): # Gather data repo_id = kwargs.pop('repo-id') description = kwargs.pop('description', None) display_name = kwargs.pop('display-name', None) auto_publish = kwargs.pop('auto-publish', None) if auto_publish: auto_publish = arg_to_bool(auto_publish) if auto_publish is None: self.context.prompt.render_failure_message(_('Value for auto-publish must be either true or false')) return try: notes = None if 'note' in kwargs and kwargs['note'] is not None: notes = args_to_notes_dict(kwargs['note'], include_none=True) importer_config = args_to_importer_config(kwargs) except InvalidConfig, e: self.context.prompt.render_failure_message(e[0]) return