diff --git a/ckan/logic/action/delete.py b/ckan/logic/action/delete.py index cdc1703a5d4..ab35bcf3101 100644 --- a/ckan/logic/action/delete.py +++ b/ckan/logic/action/delete.py @@ -105,7 +105,10 @@ def task_status_delete(context, data_dict): def vocabulary_delete(context, data_dict): model = context['model'] - vocab_id = data_dict['id'] + + vocab_id = data_dict.get('id') + if not vocab_id: + raise ValidationError({'id': _('id not in data')}) vocab_obj = model.vocabulary.Vocabulary.get(vocab_id) if vocab_obj is None: diff --git a/ckan/tests/functional/api/model/test_vocabulary.py b/ckan/tests/functional/api/model/test_vocabulary.py index 6528297ed4b..d537bf44e5d 100644 --- a/ckan/tests/functional/api/model/test_vocabulary.py +++ b/ckan/tests/functional/api/model/test_vocabulary.py @@ -343,6 +343,22 @@ def test_vocabulary_delete_not_exists(self): status=404) assert response.json['success'] == False + def test_vocabulary_delete_no_id(self): + '''Test the error response given when a user tries to delete a + vocabulary without giving the vocabulary id. + + ''' + params = {} + param_string = json.dumps(params) + response = self.app.post('/api/action/vocabulary_delete', + params=param_string, + extra_environ = {'Authorization': + str(self.sysadmin_user.apikey)}, + status=409) + assert response.json['success'] == False + assert response.json['error'].has_key('id') + assert response.json['error']['id'] == 'id not in data' + def test_vocabulary_delete_not_logged_in(self): '''Test that users who are not logged in cannot delete vocabularies.''' params = {'id': self.genre_vocab['id']}