[ckan-changes] commit/ckan: John Glover: [1371] finish task_status_update logic layer function

Bitbucket commits-noreply at bitbucket.org
Wed Oct 5 14:24:20 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/5210a80f818d/
changeset:   5210a80f818d
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-10-05 16:24:05
summary:     [1371] finish task_status_update logic layer function
affected #:  4 files (-1 bytes)

--- a/ckan/lib/dictization/model_dictize.py	Wed Oct 05 14:14:50 2011 +0100
+++ b/ckan/lib/dictization/model_dictize.py	Wed Oct 05 15:24:05 2011 +0100
@@ -191,6 +191,9 @@
 
     return result_dict 
 
+def task_status_dictize(task_status, context):
+    return table_dictize(task_status, context)
+
 ## conversion to api
 
 def group_to_api1(group, context):


--- a/ckan/lib/dictization/model_save.py	Wed Oct 05 14:14:50 2011 +0100
+++ b/ckan/lib/dictization/model_save.py	Wed Oct 05 15:24:05 2011 +0100
@@ -384,3 +384,12 @@
 
     return dictized
 
+def task_status_dict_save(task_status_dict, context):
+    model = context["model"]
+    task_status = context.get("task_status")
+    allow_partial_update = context.get("allow_partial_update", False)
+    if task_status:
+        task_status_dict["id"] = task_status.id 
+
+    task_status = table_dict_save(task_status_dict, model.TaskStatus, context)
+    return task_status


--- a/ckan/logic/action/update.py	Wed Oct 05 14:14:50 2011 +0100
+++ b/ckan/logic/action/update.py	Wed Oct 05 15:24:05 2011 +0100
@@ -12,6 +12,7 @@
                                                 package_to_api1,
                                                 package_to_api2,
                                                 resource_dictize,
+                                                task_status_dictize,
                                                 group_dictize,
                                                 group_to_api1,
                                                 group_to_api2,
@@ -20,6 +21,7 @@
                                              package_api_to_dict,
                                              group_dict_save,
                                              user_dict_save,
+                                             task_status_dict_save,
                                              package_dict_save,
                                              resource_dict_save)
 from ckan.logic.schema import (default_update_group_schema,
@@ -72,6 +74,12 @@
             error_summary[_(prettify(key))] = error[0]
     return error_summary
 
+def task_status_error_summary(error_dict):
+    error_summary = {}
+    for key, error in error_dict.iteritems():
+        error_summary[_(prettify(key))] = error[0]
+    return error_summary
+
 def _make_latest_rev_active(context, q):
 
     session = context['model'].Session
@@ -378,7 +386,14 @@
 
     data, errors = validate(data_dict, schema, context)
 
-    return {}
+    if errors:
+        model.Session.rollback()
+        raise ValidationError(errors, task_status_error_summary(errors))
+
+    task_status = task_status_dict_save(data, context)
+
+    model.Session.commit()
+    return task_status_dictize(task_status, context)
 
 def task_status_update_many(context, data_dicts):
     return {}


--- a/ckan/tests/functional/api/test_action.py	Wed Oct 05 14:14:50 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py	Wed Oct 05 15:24:05 2011 +0100
@@ -531,14 +531,39 @@
         assert resource_updated == resource_created
 
     def test_20_task_status_update(self):
-        task_status = {}
+        package = {
+            'name': u'test_task_status_update',
+            '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)
+        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']
-        print task_status_updated
+        task_status_updated.pop('id')
+        task_status_updated.pop('last_updated')
+        assert task_status_updated == task_status, (task_status_updated, task_status)
 
     def test_21_task_status_update_many(self):
         pass
@@ -558,3 +583,12 @@
             'error': {'message': 'Access denied', '__type': 'Authorization Error'}
         }
         assert res_obj == expected_res_obj, res_obj
+
+    def test_23_task_status_validation(self):
+        task_status = {} 
+        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)},
+            status=self.STATUS_409_CONFLICT
+        )

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