From 1a1400607fc871c221a29ebb19e1fa84bf08ed2d Mon Sep 17 00:00:00 2001 From: Vitor Baptista Date: Thu, 22 May 2014 16:57:23 -0300 Subject: [PATCH] [#1725] Add tests for when searching/deleting elements passing invalid filters --- ckanext/datastore/tests/test_delete.py | 18 ++++++++++++++++++ ckanext/datastore/tests/test_search.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/ckanext/datastore/tests/test_delete.py b/ckanext/datastore/tests/test_delete.py index bb7db39217a..02d5ad3bcfb 100644 --- a/ckanext/datastore/tests/test_delete.py +++ b/ckanext/datastore/tests/test_delete.py @@ -156,3 +156,21 @@ def test_delete_filters(self): self.Session.remove() self._delete() + + def test_delete_is_unsuccessful_when_called_with_invalid_filters(self): + self._create() + + data = { + 'resource_id': self.data['resource_id'], + 'filters': { + 'invalid-column-name': 'value' + } + } + postparams = '%s=1' % json.dumps(data) + auth = {'Authorization': str(self.normal_user.apikey)} + res = self.app.post('/api/action/datastore_delete', params=postparams, + extra_environ=auth, status=409) + res_dict = json.loads(res.body) + assert res_dict['success'] is False + + self._delete() diff --git a/ckanext/datastore/tests/test_search.py b/ckanext/datastore/tests/test_search.py index 1b7c9486da7..258ab01c96d 100644 --- a/ckanext/datastore/tests/test_search.py +++ b/ckanext/datastore/tests/test_search.py @@ -414,6 +414,20 @@ def test_search_table_metadata(self): res_dict = json.loads(res.body) assert res_dict['success'] is True + def test_search_is_unsuccessful_when_called_with_invalid_filters(self): + data = { + 'resource_id': self.data['resource_id'], + 'filters': { + 'invalid-column-name': 'value' + } + } + postparams = '%s=1' % json.dumps(data) + auth = {'Authorization': str(self.normal_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 + class TestDatastoreFullTextSearch(tests.WsgiAppCase): @classmethod