def test_retrieve_filter_ids_no_matches(mock_index, mock_log): mock_index.return_value = [] ids = api.retrieve_filter_ids('users', 'owner', 'foo') assert mock_log.warning.called assert ids == []
def test_retrieve_filter_ids(mock_index, mock_log): mock_index.return_value = [{'id': 1}] ids = api.retrieve_filter_ids('users', 'owner', 'foo') assert not mock_log.warning.called assert ids == [('owner', 1)]
def list_cmd(submitters, limit, page, sort, fmt, headers, name): """List series. List series on the Patchwork instance. """ LOG.debug('List series: submitters=%s, limit=%r, page=%r, sort=%r', ','.join(submitters), limit, page, sort) params = [] for submitter in submitters: if submitter.isdigit(): params.append(('submitter', submitter)) else: # we support server-side filtering by email (but not name) in 1.1 if api.version() >= (1, 1) and '@' in submitter: params.append(('submitter', submitter)) else: params.extend( api.retrieve_filter_ids('people', 'submitter', submitter)) params.extend([ ('q', name), ('page', page), ('per_page', limit), ('order', sort), ]) series = api.index('series', params) # Format and print output output = [] for series_ in series: item = [ series_.get('id'), arrow.get(series_.get('date')).humanize(), utils.trim(series_.get('name') or ''), series_.get('version'), '%s (%s)' % (series_.get('submitter').get('name'), series_.get('submitter').get('email')) ] output.append([]) for idx, header in enumerate(_list_headers): if header not in headers: continue output[-1].append(item[idx]) utils.echo_via_pager(output, headers, fmt=fmt)
def test_retrieve_filter_ids_multiple_matches_1_0(mock_index, mock_version, mock_log): mock_index.return_value = [ { 'id': 1 }, { 'id': 2 }, # incomplete but good enough ] mock_version.return_value = (1, 0) ids = api.retrieve_filter_ids('users', 'owner', 'foo') assert mock_log.warning.called assert ids == [('owner', 1), ('owner', 2)]
def list_cmd(owners, limit, page, sort, fmt, headers, name): """List bundles. List bundles on the Patchwork instance. """ LOG.debug('List bundles: owners=%s, limit=%r, page=%r, sort=%r', ','.join(owners), limit, page, sort) params = [] for owner in owners: # we support server-side filtering by username (but not email) in 1.1 if (api.version() >= (1, 1) and '@' not in owner) or owner.isdigit(): params.append(('owner', owner)) else: params.extend(api.retrieve_filter_ids('users', 'owner', owner)) params.extend([ ('q', name), ('page', page), ('per_page', limit), ('order', sort), ]) bundles = api.index('bundles', params) # Format and print output output = [] for bundle in bundles: item = [ bundle.get('id'), utils.trim(bundle.get('name') or ''), bundle.get('owner').get('username'), 'yes' if bundle.get('public') else 'no', ] output.append([]) for idx, header in enumerate(_list_headers): if header not in headers: continue output[-1].append(item[idx]) utils.echo_via_pager(output, headers, fmt=fmt)
def list_cmd(state, submitter, delegate, archived, limit, page, sort, fmt, headers, name): """List patches. List patches on the Patchwork instance. """ LOG.debug( 'List patches: states=%s, submitters=%s, delegates=%s, ' 'archived=%r', ','.join(state), ','.join(submitter), ','.join(delegate), archived) params = [] for state in state: params.append(('state', state)) for subm in submitter: # we support server-side filtering by email (but not name) in 1.1 if (api.version() >= (1, 1) and '@' in subm) or subm.isdigit(): params.append(('submitter', subm)) else: params.extend(api.retrieve_filter_ids('people', 'submitter', subm)) for delg in delegate: # we support server-side filtering by username (but not email) in 1.1 if (api.version() >= (1, 1) and '@' not in delg) or delg.isdigit(): params.append(('delegate', delg)) else: params.extend(api.retrieve_filter_ids('users', 'delegate', delg)) params.extend([ ('q', name), ('archived', 'true' if archived else 'false'), ('page', page), ('per_page', limit), ('order', sort), ]) patches = api.index('patches', params) # Format and print output output = [] for patch in patches: item = [ patch.get('id'), arrow.get(patch.get('date')).humanize(), utils.trim(patch.get('name')), '%s (%s)' % (patch.get('submitter').get('name'), patch.get('submitter').get('email')), patch.get('state'), 'yes' if patch.get('archived') else 'no', (patch.get('delegate') or {}).get('username', ''), ] output.append([]) for idx, header in enumerate(_list_headers): if header not in headers: continue output[-1].append(item[idx]) utils.echo_via_pager(output, headers, fmt=fmt)
def test_retrieve_filter_ids_too_short(mock_index): with pytest.raises(SystemExit): api.retrieve_filter_ids('users', 'owner', 'f') assert not mock_index.called