[ckan-changes] commit/ckan: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Thu Aug 4 17:32:51 UTC 2011


2 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/8d293393a9f2/
changeset:   8d293393a9f2
branch:      release-v1.4.3
user:        dread
date:        2011-08-04 19:27:32
summary:     [controllers]: #1263 Return proper error when in the API you request a logic action that does not exist.
affected #:  2 files (1.5 KB)

--- a/ckan/controllers/api.py	Wed Aug 03 16:28:15 2011 +0100
+++ b/ckan/controllers/api.py	Thu Aug 04 18:27:32 2011 +0100
@@ -133,6 +133,9 @@
     
     def action(self, logic_function):
         function = get_action(logic_function)
+        if not function:
+            return self._finish_bad_request(
+                gettext('Action name not known: %s') % str(logic_function))
         
         context = {'model': model, 'session': model.Session, 'user': c.user}
         model.Session()._context = context


--- a/ckan/tests/functional/api/test_action.py	Wed Aug 03 16:28:15 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py	Thu Aug 04 18:27:32 2011 +0100
@@ -1,5 +1,6 @@
 import json
 from pprint import pprint, pformat
+from nose.tools import assert_equal
 
 from ckan.lib.create_test_data import CreateTestData
 import ckan.model as model
@@ -123,6 +124,27 @@
         assert 'number_administered_packages' in result
         assert 'number_of_edits' in result
 
+    def test_05_user_show_edits(self):
+        postparams = '%s=1' % json.dumps({'id':'tester'})
+        res = self.app.post('/api/action/user_show', params=postparams)
+        res_obj = json.loads(res.body)
+        assert res_obj['help'] == 'Shows user details'
+        assert res_obj['success'] == True
+        result = res_obj['result']
+        assert result['name'] == 'tester'
+        assert_equal(result['about'], None)
+        assert result['number_of_edits'] >= 1
+        edit = result['activity'][-1] # first edit chronologically
+        assert_equal(edit['author'], 'tester')
+        assert 'timestamp' in edit
+        assert_equal(edit['state'], 'active')
+        assert_equal(edit['approved_timestamp'], None)
+        assert_equal(set(edit['groups']), set(('roger', 'david')))
+        assert_equal(edit['state'], 'active')
+        assert edit['message'].startswith('Creating test data.')
+        assert_equal(set(edit['packages']), set(('warandpeace', 'annakarenina')))
+        assert 'id' in edit
+
     def test_06_tag_list(self):
         postparams = '%s=1' % json.dumps({})
         res = self.app.post('/api/action/tag_list', params=postparams)
@@ -401,3 +423,11 @@
         assert res_obj['result'][0]['name'] == 'joeadmin'
         assert 'id','fullname' in res_obj['result'][0]
 
+    def test_17_bad_action(self):
+        #Empty query
+        postparams = '%s=1' % json.dumps({})
+        res = self.app.post('/api/action/bad_action_name', params=postparams,
+                            status=400)
+        res_obj = json.loads(res.body)
+        assert_equal(res_obj, u'Bad request - Action name not known: bad_action_name')
+


http://bitbucket.org/okfn/ckan/changeset/8e427c2e4ad6/
changeset:   8e427c2e4ad6
user:        dread
date:        2011-08-04 19:29:00
summary:     [merge] from release-v1.4.3.
affected #:  2 files (1.5 KB)

--- a/ckan/controllers/api.py	Thu Aug 04 15:29:41 2011 +0100
+++ b/ckan/controllers/api.py	Thu Aug 04 18:29:00 2011 +0100
@@ -133,6 +133,9 @@
     
     def action(self, logic_function):
         function = get_action(logic_function)
+        if not function:
+            return self._finish_bad_request(
+                gettext('Action name not known: %s') % str(logic_function))
         
         context = {'model': model, 'session': model.Session, 'user': c.user}
         model.Session()._context = context


--- a/ckan/tests/functional/api/test_action.py	Thu Aug 04 15:29:41 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py	Thu Aug 04 18:29:00 2011 +0100
@@ -1,5 +1,6 @@
 import json
 from pprint import pprint, pformat
+from nose.tools import assert_equal
 
 from ckan.lib.create_test_data import CreateTestData
 import ckan.model as model
@@ -123,6 +124,27 @@
         assert 'number_administered_packages' in result
         assert 'number_of_edits' in result
 
+    def test_05_user_show_edits(self):
+        postparams = '%s=1' % json.dumps({'id':'tester'})
+        res = self.app.post('/api/action/user_show', params=postparams)
+        res_obj = json.loads(res.body)
+        assert res_obj['help'] == 'Shows user details'
+        assert res_obj['success'] == True
+        result = res_obj['result']
+        assert result['name'] == 'tester'
+        assert_equal(result['about'], None)
+        assert result['number_of_edits'] >= 1
+        edit = result['activity'][-1] # first edit chronologically
+        assert_equal(edit['author'], 'tester')
+        assert 'timestamp' in edit
+        assert_equal(edit['state'], 'active')
+        assert_equal(edit['approved_timestamp'], None)
+        assert_equal(set(edit['groups']), set(('roger', 'david')))
+        assert_equal(edit['state'], 'active')
+        assert edit['message'].startswith('Creating test data.')
+        assert_equal(set(edit['packages']), set(('warandpeace', 'annakarenina')))
+        assert 'id' in edit
+
     def test_06_tag_list(self):
         postparams = '%s=1' % json.dumps({})
         res = self.app.post('/api/action/tag_list', params=postparams)
@@ -401,3 +423,11 @@
         assert res_obj['result'][0]['name'] == 'joeadmin'
         assert 'id','fullname' in res_obj['result'][0]
 
+    def test_17_bad_action(self):
+        #Empty query
+        postparams = '%s=1' % json.dumps({})
+        res = self.app.post('/api/action/bad_action_name', params=postparams,
+                            status=400)
+        res_obj = json.loads(res.body)
+        assert_equal(res_obj, u'Bad request - Action name not known: bad_action_name')
+

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list