Skip to content

Commit

Permalink
Fix content-delivery-repo list ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Holecek committed Aug 7, 2017
1 parent 1ca310c commit 93cfd26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
17 changes: 14 additions & 3 deletions pdc_client/plugins/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
("product_id", "Product ID"),
]

_ORDERING = [
'variant_arch__variant__release__release_id',
'variant_arch__variant__variant_uid',
'variant_arch__arch__name',
'service',
'repo_family',
'content_format',
'content_category',
'shadow',
'name'
]


class RepoPlugin(PDCClientPlugin):
command = 'content-delivery-repo'
Expand Down Expand Up @@ -135,9 +147,8 @@ def repo_list(self, args, data=None):
filters = extract_arguments(args, prefix='filter_')
if not filters and not data:
self.subparsers.choices.get('list').error('At least some filter must be used.')
# TODO: enable ordering; can't be done due to lack of functionality on server
# filters["ordering"] = ["release_id", "variant_uid", "arch", "service", "repo_family", "content_format", "content_category", "shadow", "name"]
repos = data or self.client.get_paged(self.client['content-delivery-repos']._, **filters)
ordering = ','.join(_ORDERING)
repos = data or self.client.get_paged(self.client['content-delivery-repos']._, ordering=ordering, **filters)

if args.json:
print(self.to_json(list(repos)))
Expand Down
18 changes: 12 additions & 6 deletions tests/repo/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,23 @@ def test_list(self, api):
self._setup_list(api)
with self.expect_output('list.txt'):
self.runner.run(['content-delivery-repo', 'list', '--content-format', 'iso'])
self.assertEqual(api.calls['content-delivery-repos'],
[('GET', {'page': 1, 'content_format': 'iso'}),
('GET', {'page': 2, 'content_format': 'iso'})])
result = api.calls['content-delivery-repos']
# Skip checking 'ordering'.
ordering = result[0][1]['ordering']
self.assertEqual(result,
[('GET', {'page': 1, 'content_format': 'iso', 'ordering': ordering}),
('GET', {'page': 2, 'content_format': 'iso', 'ordering': ordering})])

def test_list_json(self, api):
self._setup_list(api)
with self.expect_output('list.json', parse_json=True):
self.runner.run(['--json', 'content-delivery-repo', 'list', '--content-format', 'iso'])
self.assertEqual(api.calls['content-delivery-repos'],
[('GET', {'page': 1, 'content_format': 'iso'}),
('GET', {'page': 2, 'content_format': 'iso'})])
result = api.calls['content-delivery-repos']
# Skip checking 'ordering'.
ordering = result[0][1]['ordering']
self.assertEqual(result,
[('GET', {'page': 1, 'content_format': 'iso', 'ordering': ordering}),
('GET', {'page': 2, 'content_format': 'iso', 'ordering': ordering})])

def _setup_detail(self, api):
self.repo_detail = {
Expand Down

0 comments on commit 93cfd26

Please sign in to comment.