Skip to content

Commit

Permalink
Make pdc client accept global component name for info instead of id
Browse files Browse the repository at this point in the history
JIRA: PDC-1225
  • Loading branch information
ycheng-aa committed Nov 30, 2015
1 parent 2a5ab66 commit 05af64f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
7 changes: 5 additions & 2 deletions pdc_client/plugins/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def register(self):
list_parser.set_defaults(func=self.list_global_components)

info_parser = self.add_action('info', help='display details of a global component')
info_parser.add_argument('global_component_id', metavar='GLOBAL_COMPONENT_ID')
info_parser.add_argument('global_component_name', metavar='GLOBAL_COMPONENT_NAME')
info_parser.set_defaults(func=self.global_component_info)

update_parser = self.add_action('update', help='update an existing global component')
Expand Down Expand Up @@ -83,7 +83,10 @@ def _get_component_id(self, args):
return None

def global_component_info(self, args, global_component_id=None):
global_component_id = global_component_id or args.global_component_id
if not global_component_id:
global_component_id = self._get_component_id(args.global_component_name)
if not global_component_id:
self.subparsers.choices.get('info').error("This global component doesn't exist.\n")
global_component = self.client['global-components'][global_component_id]._()

component_contacts = get_paged(self.client['global-component-contacts']._,
Expand Down
26 changes: 10 additions & 16 deletions tests/component/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_list_multi_page(self, api):
('GET', {'page': 2, 'label': 'test label'})])

def test_detail(self, api):
api.add_endpoint('global-components', 'GET', [self.detail])
self._setup_detail(api)
api.add_endpoint('global-component-contacts',
'GET',
Expand All @@ -71,15 +72,11 @@ def test_detail(self, api):
}
]})
with self.expect_output('global_component/detail.txt'):
self.runner.run(['global-component', 'info', '1'])
self.runner.run(['global-component', 'info', 'Test Global Component'])
self.assertEqual(api.calls,
{'global-components/1': [('GET', {})],
'global-component-contacts':
[('GET',
{'component': 'Test Global Component',
'page': 1})
]
})
{'global-components': [('GET', {'name': 'Test Global Component'})],
'global-components/1': [('GET', {})],
'global-component-contacts': [('GET', {'component': 'Test Global Component', 'page': 1})]})

def test_update(self, api):
api.add_endpoint('global-components', 'GET', [self.detail])
Expand Down Expand Up @@ -149,17 +146,14 @@ def test_info_json(self, api):
'next': None,
'previous': None,
'results': []})
api.add_endpoint('global-components', 'GET', [self.detail])
self._setup_detail(api)
with self.expect_output('global_component/detail.json', parse_json=True):
self.runner.run(['--json', 'global-component', 'info', '1'])
self.runner.run(['--json', 'global-component', 'info', 'Test Global Component'])
self.assertEqual(api.calls,
{'global-components/1': [('GET', {})],
'global-component-contacts':
[('GET',
{'component': 'Test Global Component',
'page': 1})
]
})
{'global-components': [('GET', {'name': 'Test Global Component'})],
'global-components/1': [('GET', {})],
'global-component-contacts': [('GET', {'component': 'Test Global Component', 'page': 1})]})

def test_list_json(self, api):
api.add_endpoint('global-components', 'GET', [self.detail])
Expand Down

0 comments on commit 05af64f

Please sign in to comment.