Skip to content

Commit

Permalink
Tweak vocabulary_show() arguments
Browse files Browse the repository at this point in the history
Be consistent with other *_show() logic functions: accept an 'id'
argument that can be either the vocab ID or the name.
  • Loading branch information
Sean Hammond committed Feb 17, 2012
1 parent dff9f7a commit aac7586
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
18 changes: 6 additions & 12 deletions ckan/logic/action/get.py
Expand Up @@ -999,18 +999,12 @@ def vocabulary_list(context, data_dict):

def vocabulary_show(context, data_dict):
model = context['model']

if data_dict.has_key('id'):
vocabulary = model.vocabulary.Vocabulary.get(data_dict['id'])
if vocabulary is None:
raise NotFound
elif data_dict.has_key('name'):
vocabulary = model.vocabulary.Vocabulary.get(data_dict['name'])
if vocabulary is None:
raise NotFound
else:
raise NotFound

vocab_id = data_dict.get('id')
if not vocab_id:
raise ValidationError({'id': _('id not in data')})
vocabulary = model.vocabulary.Vocabulary.get(vocab_id)
if vocabulary is None:
raise NotFound(_('Could not find vocabulary "%s"') % vocab_id)
vocabulary_dict = vocabulary_dictize(vocabulary, context)
return vocabulary_dict

Expand Down
4 changes: 2 additions & 2 deletions ckan/tests/functional/api/model/test_vocabulary.py
Expand Up @@ -60,7 +60,7 @@ def _create_vocabulary(self, vocab_name=None, user=None):
params = {'id': created_vocab['id']}
response = self._post('/api/action/vocabulary_show', params)
# Check that retrieving the vocab by name gives the same result.
by_name_params = {'name': created_vocab['name']}
by_name_params = {'id': created_vocab['name']}
assert response == self._post('/api/action/vocabulary_show',
by_name_params)
# Check that it matches what we created.
Expand Down Expand Up @@ -101,7 +101,7 @@ def _update_vocabulary(self, params, user=None):
params = {'id': updated_vocab['id']}
response = self._post('/api/action/vocabulary_show', params)
# Check that retrieving the vocab by name gives the same result.
by_name_params = {'name': updated_vocab['name']}
by_name_params = {'id': updated_vocab['name']}
assert response == self._post('/api/action/vocabulary_show',
by_name_params)
# Check that it matches what we created.
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/functional/test_tag_vocab.py
Expand Up @@ -187,7 +187,7 @@ def teardown_class(cls):
model.repo.rebuild_db()

def _get_vocab_id(self, vocab_name):
params = json.dumps({'name': vocab_name})
params = json.dumps({'id': vocab_name})
response = self.app.post('/api/action/vocabulary_show', params=params)
assert json.loads(response.body)['success']
return json.loads(response.body)['result']['id']
Expand Down

0 comments on commit aac7586

Please sign in to comment.