diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index aeeabc9e8e2..99e5491f653 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -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 diff --git a/ckan/tests/functional/api/model/test_vocabulary.py b/ckan/tests/functional/api/model/test_vocabulary.py index b351eabea06..608f98698fa 100644 --- a/ckan/tests/functional/api/model/test_vocabulary.py +++ b/ckan/tests/functional/api/model/test_vocabulary.py @@ -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. @@ -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. diff --git a/ckan/tests/functional/test_tag_vocab.py b/ckan/tests/functional/test_tag_vocab.py index 976a8122edf..226f018544f 100644 --- a/ckan/tests/functional/test_tag_vocab.py +++ b/ckan/tests/functional/test_tag_vocab.py @@ -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']