def __init__(self, context): m = _('list bindings with consumer actions with a status of pending or failed') CriteriaCommand.__init__(self, self.run, 'unconfirmed', m, filtering=False) self.add_flag(PulpCliFlag('--bind', _('limit search to bindings with unconfirmed bind actions'))) self.add_flag(PulpCliFlag('--unbind', _('limit search to bindings with unconfirmed unbind actions'))) self.context = context
def parse_key_value(args): """ Meant to replace the CriteriaCommand _parse_key_value method. The docstring below was copied from that implementation. parses the raw user input, taken as a list of strings in the format 'name=value', into a list of tuples in the format (name, value). :param args: list of raw strings passed by the user on the command line. :type args: list of basestrings :return: new list of tuples in the format (name, value) """ def translate(key_value_tuple): """ :param key_value_tuple: single key/value tuple to translate :return: new key-value tuple to use """ for orig_key, translated_key in TRANSLATIONS.items(): if key_value_tuple[0] == orig_key: encoded_value = version_utils.encode(key_value_tuple[1]) return translated_key, encoded_value return key_value_tuple base_parsed_list = CriteriaCommand._parse_key_value(args) translated_list = map(translate, base_parsed_list) return translated_list
def __init__(self, context): m = _( 'list bindings with consumer actions with a status of pending or failed' ) CriteriaCommand.__init__(self, self.run, 'unconfirmed', m, filtering=False) self.add_flag( PulpCliFlag( '--bind', _('limit search to bindings with unconfirmed bind actions'))) self.add_flag( PulpCliFlag( '--unbind', _('limit search to bindings with unconfirmed unbind actions'))) self.context = context
def __init__(self, context): PulpCliSection.__init__(self, 'user', 'manage users') self.context = context self.prompt = context.prompt # for easier access # Common Options login_option = PulpCliOption('--login', 'uniquely identifies the user; only alphanumeric, -, ., and _ allowed', required=True, validate_func=validators.id_validator_allow_dots) name_option = PulpCliOption('--name', 'user-readable full name of the user', required=False) # Create command create_command = PulpCliCommand('create', 'creates a user', self.create) create_command.add_option(login_option) create_command.add_option(PulpCliOption('--password', 'password for the new user, if you do not want to be prompted for one', required=False)) create_command.add_option(name_option) self.add_command(create_command) # Update Command update_command = PulpCliCommand('update', 'changes metadata of an existing user', self.update) update_command.add_option(PulpCliOption('--login', 'identifies the user to be updated', required=True)) update_command.add_option(name_option) update_command.add_option(PulpCliOption('--password', 'new password for the user, use -p if you want to be prompted for the password', required=False)) update_command.add_option(PulpCliFlag('-p', 'if specified, you will be prompted to enter new password for the user')) self.add_command(update_command) # Delete Command delete_command = PulpCliCommand('delete', 'deletes a user', self.delete) delete_command.add_option(PulpCliOption('--login', 'identifies the user to be deleted', required=True)) self.add_command(delete_command) # List Command list_command = PulpCliCommand('list', 'lists summary of users registered to the Pulp server', self.list) list_command.add_option(PulpCliFlag('--details', 'if specified, all the user information is displayed')) list_command.add_option(PulpCliOption('--fields', 'comma-separated list of user fields; if specified, only the given fields will displayed', required=False)) self.add_command(list_command) # Search Command self.add_command(CriteriaCommand(self.search, include_search=True))
def __init__(self, context): super(ConsumerGroupMemberSection, self).__init__('members', _('manage members of consumer groups')) self.context = context self.prompt = context.prompt id_option = PulpCliOption('--consumer-group-id', _('id of a consumer group'), required=True) list_command = PulpCliCommand('list', _('list of consumers in a particular group'), self.list) list_command.add_option(id_option) self.add_command(list_command) add_command = CriteriaCommand(self.add, name='add', include_search=False, description=_('add consumers based on search parameters')) add_command.add_option(id_option) self.add_command(add_command) remove_command = CriteriaCommand(self.remove, name='remove', include_search=False, description=_('remove consumers based on search parameters')) remove_command.add_option(id_option) self.add_command(remove_command)
def test_valid(self): CriteriaCommand._validate_sort(['name,descending'])
def test_empty(self): ret = CriteriaCommand._parse_sort([]) self.assertEqual(ret, [])
def test_multiple_args(self): ret = CriteriaCommand._parse_key_value(['id=repo1', 'name=foo']) self.assertEqual(ret, [['id', 'repo1'], ['name', 'foo']])
def test_empty(self): CriteriaCommand._validate_sort([])
def __init__(self, context): CriteriaCommand.__init__(self, self.run) self.context = context
def test_trailing_comma(self): field_name, direction = CriteriaCommand._explode_sort_arg_pieces('name,') self.assertEqual(field_name, 'name') self.assertEqual(direction, 'ascending')
def test_without_criteria(self): self.command = CriteriaCommand(mock.MagicMock(), include_search=False) self.assertEqual(len(self.command.option_groups), 1) options_present = set([option.name for option in self.command.options]) self.assertEqual(options_present, set(['--filters']))
def test_without_filtering(self): self.command = CriteriaCommand(mock.MagicMock(), filtering=False) self.assertEqual(len(self.command.option_groups), 0) options_present = set([option.name for option in self.command.options]) self.assertTrue('--filters' not in options_present)
def setUp(self): self.command = CriteriaCommand(mock.MagicMock())
def test_valid(self): DATA = ('name', 'id,descending') ret = CriteriaCommand._parse_sort(DATA) self.assertEqual(ret, [('name', 'ascending'), ('id', 'descending')])
def test_simple(self): field_name, direction = CriteriaCommand._explode_sort_arg_pieces('name,descending') self.assertEqual(field_name, 'name') self.assertEqual(direction, 'descending')
def test_basic(self): ret = CriteriaCommand._parse_key_value(['id=repo1']) self.assertEqual(ret, [['id', 'repo1']])
def test_trailing_comma(self): field_name, direction = CriteriaCommand._explode_sort_arg_pieces( 'name,') self.assertEqual(field_name, 'name') self.assertEqual(direction, 'ascending')
def test_multiple_equals(self): # the second '=' should not be split ret = CriteriaCommand._parse_key_value(['id=repo=1']) self.assertEqual(ret, [['id', 'repo=1']])
def test_simple(self): field_name, direction = CriteriaCommand._explode_sort_arg_pieces( 'name,descending') self.assertEqual(field_name, 'name') self.assertEqual(direction, 'descending')