Skip to content

Commit

Permalink
Fix vocabulary_update() 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 0e892f8 commit 05f1273
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ckan/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,9 @@ def group_update_rest(context, data_dict):

def vocabulary_update(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')})

model.Session.remove()
model.Session()._context = context
Expand Down
12 changes: 12 additions & 0 deletions ckan/tests/functional/api/model/test_vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ def test_vocabulary_update_no_name(self):
status=409)
assert response.json['success'] == False

def test_vocabulary_update_no_id(self):
params = {'name': 'bagel radio'}
param_string = json.dumps(params)
response = self.app.post('/api/action/vocabulary_update',
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_update_not_logged_in(self):
'''Test that users who are not logged in cannot update vocabularies.'''
params = {'id': self.genre_vocab['id']}
Expand Down

0 comments on commit 05f1273

Please sign in to comment.