Skip to content

Commit

Permalink
Fix vocabulary_delete() when no id given
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Feb 17, 2012
1 parent 05f1273 commit 9e6872a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ckan/logic/action/delete.py
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions ckan/tests/functional/api/model/test_vocabulary.py
Expand Up @@ -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']}
Expand Down

0 comments on commit 9e6872a

Please sign in to comment.