[ckan-changes] commit/ckan: John Glover: [1371] add task_status_show get action

Bitbucket commits-noreply at bitbucket.org
Wed Oct 5 15:30:18 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/212fcbb9b5f7/
changeset:   212fcbb9b5f7
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-10-05 17:29:54
summary:     [1371] add task_status_show get action
affected #:  3 files (-1 bytes)

--- a/ckan/logic/action/get.py	Wed Oct 05 15:47:36 2011 +0100
+++ b/ckan/logic/action/get.py	Wed Oct 05 16:29:54 2011 +0100
@@ -13,6 +13,7 @@
                                                 group_dictize,
                                                 group_list_dictize,
                                                 tag_dictize,
+                                                task_status_dictize,
                                                 user_dictize)
 
 from ckan.lib.dictization.model_dictize import (package_to_api1,
@@ -739,3 +740,20 @@
     q = q.limit(limit)
     results = [r for r in q]
     return {'count': count, 'results': results}
+
+def task_status_show(context, data_dict):
+    model = context['model']
+    id = data_dict['id']
+
+    query = model.Session.query(model.TaskStatus)
+
+    task_status = model.TaskStatus.get(id)
+    context['task_status'] = task_status
+
+    if task_status is None:
+        raise NotFound
+
+    check_access('task_status_show', context, data_dict)
+
+    task_status_dict = task_status_dictize(task_status, context)
+    return task_status_dict


--- a/ckan/logic/auth/get.py	Wed Oct 05 15:47:36 2011 +0100
+++ b/ckan/logic/auth/get.py	Wed Oct 05 16:29:54 2011 +0100
@@ -129,6 +129,9 @@
 def format_autocomplete(context, data_dict):
     return {'success': True}
 
+def task_status_show(context, data_dict):
+    return {'success': True}
+
 ## Modifications for rest api
 
 def package_show_rest(context, data_dict):


--- a/ckan/tests/functional/api/test_action.py	Wed Oct 05 15:47:36 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py	Wed Oct 05 16:29:54 2011 +0100
@@ -533,13 +533,12 @@
     def test_20_task_status_update(self):
         package = {
             'name': u'test_task_status_update',
+            'title': u'A Novel By Tolstoy',
             'resources': [{
                 'description': u'Full text.',
                 'format': u'plain text',
                 'url': u'http://www.annakarenina.com/download/'
-            }],
-            'title': u'A Novel By Tolstoy',
-            'url': u'http://www.annakarenina.com',
+            }]
         }
 
         postparams = '%s=1' % json.dumps(package)
@@ -603,3 +602,45 @@
             extra_environ={'Authorization': str(self.sysadmin_user.apikey)},
             status=self.STATUS_409_CONFLICT
         )
+
+    def test_24_task_status_show(self):
+        package = {
+            'name': u'test_task_status_show',
+            'title': u'A Novel By Tolstoy',
+            'resources': [{
+                'description': u'Full text.',
+                'format': u'plain text',
+                'url': u'http://www.annakarenina.com/download/'
+            }]
+        }
+
+        postparams = '%s=1' % json.dumps(package)
+        res = self.app.post('/api/action/package_create', params=postparams,
+                            extra_environ={'Authorization': 'tester'})
+        package_created = json.loads(res.body)['result']
+
+        task_status = {
+            'entity_id': package_created['id'],
+            'entity_type': u'package',
+            'task_type': u'test_task',
+            'key': u'test_key',
+            'value': u'test_value',
+            'state': u'test_state'
+        }
+        postparams = '%s=1' % json.dumps(task_status)
+        res = self.app.post(
+            '/api/action/task_status_update', params=postparams,
+            extra_environ={'Authorization': str(self.sysadmin_user.apikey)},
+        )
+        task_status_updated = json.loads(res.body)['result']
+
+        postparams = '%s=1' % json.dumps({'id': task_status_updated['id']})
+        res = self.app.post(
+            '/api/action/task_status_show', params=postparams,
+            extra_environ={'Authorization': str(self.sysadmin_user.apikey)},
+        )
+        task_status_show = json.loads(res.body)['result']
+
+        task_status_show.pop('last_updated')
+        task_status_updated.pop('last_updated')
+        assert task_status_show == task_status_updated, (task_status_show, task_status_updated)

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