Skip to content

Commit

Permalink
pdc global-component update should take its name instead of ID
Browse files Browse the repository at this point in the history
When update the global-component, using GLOBAL_COMPONENT_NAME
instead of GLOBAL_COMPONENT_ID.

JIRA: PDC-1157
  • Loading branch information
bliuredhat committed Nov 14, 2015
1 parent 05280ef commit 5fc997e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 16 additions & 4 deletions pdc_client/plugins/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# http://opensource.org/licenses/MIT
#
import json
import sys

from pdc_client import get_paged
from pdc_client.plugin_helpers import (PDCClientPlugin,
Expand All @@ -29,7 +30,7 @@ def register(self):
info_parser.set_defaults(func=self.global_component_info)

update_parser = self.add_action('update', help='update an existing global component')
update_parser.add_argument('global_component_id', metavar='GLOBAL_COMPONENT_ID')
update_parser.add_argument('global_component_name', metavar='GLOBAL_COMPONENT_NAME')
self.add_global_component_arguments(update_parser)
update_parser.set_defaults(func=self.global_component_update)

Expand Down Expand Up @@ -64,6 +65,13 @@ def list_global_components(self, args):
global_component['id'],
global_component['name'])

def get_component_id(self, args):
global_component = self.client['global-components']._(name=args)
if global_component['count']:
return str(global_component['results'][0]['id'])
else:
return None

def global_component_info(self, args, global_component_id=None):
global_component_id = global_component_id or args.global_component_id
global_component = self.client['global-components'][global_component_id]._()
Expand Down Expand Up @@ -104,13 +112,17 @@ def global_component_create(self, args):

def global_component_update(self, args):
data = extract_arguments(args)
global_component_id = self.get_component_id(args.global_component_name)
if not global_component_id:
sys.stderr.write("This global component don't exist")
sys.exit(1)
if data:
self.logger.debug('Updating global component %s with data %r',
args.global_component_id, data)
self.client['global-components'][args.global_component_id]._ += data
global_component_id, data)
self.client['global-components'][global_component_id]._ += data
else:
self.logger.debug('Empty data, skipping request')
self.global_component_info(args)
self.global_component_info(args, global_component_id)


class ReleaseComponentPlugin(PDCClientPlugin):
Expand Down
8 changes: 5 additions & 3 deletions pdc_client/tests/component/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ def test_detail(self, api):
{'global-components/1': [('GET', {})]})

def test_update(self, api):
api.add_endpoint('global-components', 'GET', [self.detail])
self._setup_detail(api)
api.add_endpoint('global-components/1', 'PATCH', {})
with self.expect_output('global_component/detail.txt'):
self.runner.run(['global-component', 'update', '1', '--name', 'new test name'])
self.runner.run(['global-component', 'update', 'Test Global Component', '--name', 'new test name'])
self.assertDictEqual(api.calls,
{'global-components/1': [('PATCH', {'name': 'new test name'}),
('GET', {})]})
{
'global-components': [('GET', {'name': 'Test Global Component'})],
'global-components/1': [('PATCH', {'name': 'new test name'}), ('GET', {})]})

def test_create(self, api):
api.add_endpoint('global-components', 'POST', self.detail)
Expand Down

0 comments on commit 5fc997e

Please sign in to comment.