Skip to content

Commit

Permalink
[#1394][logic]: Fixed misleading validation error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Jan 3, 2012
1 parent 5a3520f commit c51db1a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ckan/logic/action/update.py
Expand Up @@ -41,7 +41,7 @@ def package_error_summary(error_dict):
error_summary = {}
for key, error in error_dict.iteritems():
if key == 'resources':
error_summary[_('Resources')] = _('Package resource(s) incomplete')
error_summary[_('Resources')] = _('Package resource(s) invalid')
elif key == 'extras':
error_summary[_('Extras')] = _('Missing Value')
elif key == 'extras_validation':
Expand Down Expand Up @@ -339,7 +339,7 @@ def group_update(context, data_dict):
return group_dictize(group, context)

def user_update(context, data_dict):
'''Updates the user's details'''
'''Updates the user\'s details'''

model = context['model']
user = context['user']
Expand Down
27 changes: 27 additions & 0 deletions ckan/tests/functional/api/model/test_package.py
Expand Up @@ -486,6 +486,33 @@ def test_package_update_ok_by_id_by_put(self):
def test_entity_update_ok_by_name_by_put(self):
self.assert_package_update_ok('name', 'put')

def test_package_update_invalid(self):
old_fixture_data = {
'name': self.package_fixture_data['name'],
}
new_fixture_data = {
'name':u'somethingnew',
'resources': [{
u'url':u'http://blah.com/file1.xml',
u'size':u'abc', # INVALID
},{
u'url':u'http://blah.com/file2.xml',
u'size':u'400',
u'last_modified':u'123', # INVALID
}],
}
self.create_package_roles_revision(old_fixture_data)
pkg = self.get_package_by_name(old_fixture_data['name'])
offset = self.offset('/rest/dataset/%s' % pkg.name)
params = '%s=1' % self.dumps(new_fixture_data)
res = self.app.post(offset, params=params,
status=self.STATUS_409_CONFLICT,
extra_environ=self.extra_environ)
res_dict = self.loads(res.body)
assert len(res_dict['resources']) == 2, res_dict['resources']
assert_equal(res_dict['resources'][0], {u'size': [u'Invalid integer']})
assert_equal(res_dict['resources'][1], {u'last_modified': [u'Date format incorrect']})

def test_package_update_delete_last_extra(self):
old_fixture_data = {
'name': self.package_fixture_data['name'],
Expand Down
28 changes: 28 additions & 0 deletions ckan/tests/functional/test_package.py
Expand Up @@ -821,6 +821,34 @@ def test_edit_all_fields(self):
finally:
self._reset_data()

# NB: Cannot test resources now because it is all javascript!
## def test_edit_invalid_resource(self):
## try:
## # Create new dataset
## pkg_name = u'test_res'
## CreateTestData.create_arbitrary({'name': pkg_name,
## 'resources': [{'url': '1.pdf'}]})

## # Edit it
## pkg = model.Package.by_name(pkg_name)
## offset = url_for(controller='package', action='edit', id=pkg.name)
## res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER':'testadmin'})
## assert 'Edit - Datasets' in res, res

## pkg = model.Package.by_name(pkg_name)

## # Amend form
## fv = res.forms['dataset-edit']

## fv['resources__0__size'] = 'abc'
## res = fv.submit('save', extra_environ={'REMOTE_USER':'testadmin'})

## # Check dataset page
## assert 'Errors in form' in res, res
## assert 'Package resource(s) invalid' in res, res
## assert 'Resource 1' in res, res
## finally:
## self._reset_data()

def test_edit_bad_log_message(self):
fv = self.res.forms['dataset-edit']
Expand Down

0 comments on commit c51db1a

Please sign in to comment.