Skip to content

Commit

Permalink
pdc command take release and name as parameters instead of id.
Browse files Browse the repository at this point in the history
JIRA: PDC-1159
  • Loading branch information
ycheng-aa committed Nov 16, 2015
1 parent b819d91 commit 63152c9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 11 deletions.
21 changes: 17 additions & 4 deletions pdc_client/plugins/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Licensed under The MIT License (MIT)
# http://opensource.org/licenses/MIT
#
import sys
import json

from pdc_client import get_paged
Expand Down Expand Up @@ -144,7 +145,8 @@ def register(self):
info_parser.set_defaults(func=self.release_component_info)

update_parser = self.add_action('update', help='update an existing release component')
update_parser.add_argument('release_component_id', metavar='RELEASE_COMPONENT_ID')
update_parser.add_argument('release', metavar='RELEASE')
update_parser.add_argument('name', metavar='NAME')
self.add_release_component_arguments(update_parser)
update_parser.set_defaults(func=self.release_component_update)

Expand Down Expand Up @@ -245,14 +247,25 @@ def release_component_create(self, args):
response = self.client['release-components']._(data)
self.release_component_info(args, response['id'])

def _get_release_component_id(self, release, component_name):
release_components = self.client['release-components']._(name=component_name, release=release)
if not release_components['count']:
return None
return release_components['results'][0]['id']

def release_component_update(self, args):
data = extract_arguments(args)
release_component_id = self._get_release_component_id(args.release, args.name)
if not release_component_id:
sys.stderr.write("The specified release component doesn't exist.\n")
sys.exit(1)
args.release_component_id = release_component_id
if args.active is not None:
data['active'] = args.active
if data:
self.logger.debug('Updating release component %s with data %r',
args.release_component_id, data)
self.client['release-components'][args.release_component_id]._ += data
self.logger.debug('Updating release component %d with data %r',
release_component_id, data)
self.client['release-components'][release_component_id]._ += data
else:
self.logger.debug('Empty data, skipping request')
self.release_component_info(args)
Expand Down
59 changes: 52 additions & 7 deletions pdc_client/tests/component/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,51 @@ def setUp(self):
def _setup_detail(self, api):
api.add_endpoint('release-components/1', 'GET', self.detail)

def _setup_list_filter(self, api):
filter_result = {
"count": 1,
"next": None,
"previous": None,
"results": [
{
'id': '1',
'release': {
'release_id': 'test_release',
'active': True
},
'bugzilla_component': None,
'brew_package': None,
'global_component': 'test_global_component',
'name': 'Test Release Component',
'dist_git_branch': 'test_branch',
'dist_git_web_url': 'http://pkgs.example.com/test_release_component',
'active': True,
'type': 'rpm',
'srpm': None,
'contacts': [
{
'url': 'http://example.com/release-components/1/contacts/1/',
'contact_role': 'test_role_a',
'contact': {
'mail_name': 'Test Maillist',
'email': 'test_mail@example.com'
}
},
{
'url': 'http://example.com/release-components/1/contacts/2/',
'contact_role': 'test_role_b',
'contact': {
'username': 'Test User',
'email': 'test_user@example.com'
}
}
]
}
]
}

api.add_endpoint('release-components', 'GET', filter_result)

def test_list_without_filters(self, api):
with self.expect_failure():
self.runner.run(['release-component', 'list'])
Expand Down Expand Up @@ -309,19 +354,19 @@ def test_update(self, api):
}
]})
self._setup_detail(api)
self._setup_list_filter(api)
api.add_endpoint('release-components/1', 'PATCH', {})
with self.expect_output('release_component/detail.txt'):
self.runner.run(['release-component', 'update', '1', '--name', 'new test name'])
self.runner.run(['release-component', 'update', 'test_release', 'Test Release Component',
'--name', 'new test name'])
self.assertDictEqual(api.calls,
{'release-components/1': [('PATCH', {'name': 'new test name'}),
{'release-components': [
('GET', {'name': 'Test Release Component', 'release': 'test_release'})],
'release-components/1': [('PATCH', {'name': 'new test name'}),
('GET', {})],
'release-component-contacts':
[('GET',
{'component': 'Test Release Component',
'page': 1,
'release': 'test_release'})
]
})
{'component': 'Test Release Component', 'page': 1, 'release': 'test_release'})]})

def test_create(self, api):
api.add_endpoint('release-component-contacts',
Expand Down

0 comments on commit 63152c9

Please sign in to comment.