Skip to content

Commit

Permalink
[#686] Fix datastore validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Mar 22, 2013
1 parent 818e605 commit 5e6c282
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ckanext/datastore/db.py
Expand Up @@ -770,8 +770,8 @@ def _sort(context, data_dict, field_ids):

if field not in field_ids:
raise ValidationError({
'sort': [u'field "{0}" not it table'.format(
unicode(field, 'utf-8'))]
'sort': [u'field "{0}" not in table'.format(
field)]
})
if sort.lower() not in ('asc', 'desc'):
raise ValidationError({
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def search(context, data_dict):
id = data_dict['resource_id']
result = context['connection'].execute(
u"(SELECT 1 FROM pg_tables where tablename = '{0}') union"
u"(SELECT 1 FROM pg_views where viewname = '{0}')".format(id)
u"(SELECT 1 FROM pg_views where viewname = '{0}')".format(id)
).fetchone()
if not result:
raise ValidationError({
Expand Down
11 changes: 11 additions & 0 deletions ckanext/datastore/tests/test_search.py
Expand Up @@ -196,6 +196,17 @@ def test_search_sort(self):

assert result['records'] == self.expected_records[::-1]

def test_search_invalid(self):
data = {'resource_id': self.data['resource_id'],
'sort': u'f\xfc\xfc asc'}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/datastore_search', params=postparams,
extra_environ=auth, status=409)
res_dict = json.loads(res.body)
assert res_dict['success'] is False
assert res_dict['error']['sort'][0] == u'field "f\xfc\xfc" not in table'

def test_search_limit(self):
data = {'resource_id': self.data['resource_id'],
'limit': 1}
Expand Down

0 comments on commit 5e6c282

Please sign in to comment.