[ckan-changes] commit/ckan: John Glover: [logic] Make task_status_show work with an (entity_type, task_type, key) tuple as well as a task_status ID

Bitbucket commits-noreply at bitbucket.org
Thu Nov 3 16:47:00 UTC 2011


1 new commit in ckan:


https://bitbucket.org/okfn/ckan/changeset/8dbd4a0adf67/
changeset:   8dbd4a0adf67
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-11-03 17:46:52
summary:     [logic] Make task_status_show work with an (entity_type, task_type, key) tuple as well as a task_status ID
affected #:  2 files

diff -r 1cab385cf5fb72771c3d3c14375f108381b984bb -r 8dbd4a0adf67298316587b9e200c46440a7ef283 ckan/logic/action/get.py
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -790,11 +790,19 @@
 
 def task_status_show(context, data_dict):
     model = context['model']
-    id = data_dict['id']
+    id = data_dict.get('id')
 
-    query = model.Session.query(model.TaskStatus)
+    if id:
+        task_status = model.TaskStatus.get(id)
+    else:
+        query = model.Session.query(model.TaskStatus)\
+            .filter(and_(
+                model.TaskStatus.entity_type == data_dict['entity_type'],
+                model.TaskStatus.task_type == data_dict['task_type'],
+                model.TaskStatus.key == data_dict['key']
+            ))
+        task_status = query.first()
 
-    task_status = model.TaskStatus.get(id)
     context['task_status'] = task_status
 
     if task_status is None:


diff -r 1cab385cf5fb72771c3d3c14375f108381b984bb -r 8dbd4a0adf67298316587b9e200c46440a7ef283 ckan/tests/functional/api/test_action.py
--- a/ckan/tests/functional/api/test_action.py
+++ b/ckan/tests/functional/api/test_action.py
@@ -667,6 +667,7 @@
         )
         task_status_updated = json.loads(res.body)['result']
 
+        # make sure show works when giving a task status ID
         postparams = '%s=1' % json.dumps({'id': task_status_updated['id']})
         res = self.app.post(
             '/api/action/task_status_show', params=postparams,
@@ -678,6 +679,21 @@
         task_status_updated.pop('last_updated')
         assert task_status_show == task_status_updated, (task_status_show, task_status_updated)
 
+        # make sure show works when giving a (entity_id, task_type, key) tuple
+        postparams = '%s=1' % json.dumps({
+            'entity_type': task_status['entity_type'],
+            'task_type': task_status['task_type'],
+            'key': task_status['key']
+        })
+        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')
+        assert task_status_show == task_status_updated, (task_status_show, task_status_updated)
+
     def test_25_task_status_delete(self):
         package_created = self._add_basic_package(u'test_task_status_delete')

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