From 5e6c282a7a831b128ccafe10ed387c7ad32105bf Mon Sep 17 00:00:00 2001 From: Dominik Moritz Date: Fri, 22 Mar 2013 15:36:55 +0100 Subject: [PATCH] [#686] Fix datastore validation error --- ckanext/datastore/db.py | 6 +++--- ckanext/datastore/tests/test_search.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ckanext/datastore/db.py b/ckanext/datastore/db.py index bc442d9d152..fd2fa2999e5 100644 --- a/ckanext/datastore/db.py +++ b/ckanext/datastore/db.py @@ -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({ @@ -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({ diff --git a/ckanext/datastore/tests/test_search.py b/ckanext/datastore/tests/test_search.py index 10b4e66c7de..85ad9727cca 100644 --- a/ckanext/datastore/tests/test_search.py +++ b/ckanext/datastore/tests/test_search.py @@ -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}