[ckan-changes] commit/ckan: John Glover: [1371] add test_status_delete action to logic layer

Bitbucket commits-noreply at bitbucket.org
Wed Oct 5 15:49:24 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/00dd4f39a248/
changeset:   00dd4f39a248
branch:      feature-1371-task-status-logic-layer
user:        John Glover
date:        2011-10-05 17:48:59
summary:     [1371] add test_status_delete action to logic layer
affected #:  3 files (-1 bytes)

--- a/ckan/logic/action/delete.py	Wed Oct 05 16:29:54 2011 +0100
+++ b/ckan/logic/action/delete.py	Wed Oct 05 16:48:59 2011 +0100
@@ -87,3 +87,19 @@
 
     model.repo.commit()
 
+def task_status_delete(context, data_dict):
+    model = context['model']
+    user = context['user']
+    id = data_dict['id']
+    model.Session.remove()
+    model.Session()._context = context
+
+    entity = model.TaskStatus.get(id)
+
+    if entity is None:
+        raise NotFound
+
+    check_access('task_status_delete', context, data_dict)
+
+    entity.delete()
+    model.Session.commit()


--- a/ckan/logic/auth/delete.py	Wed Oct 05 16:29:54 2011 +0100
+++ b/ckan/logic/auth/delete.py	Wed Oct 05 16:48:59 2011 +0100
@@ -46,3 +46,12 @@
 def revision_delete(context, data_dict):
     return {'success': False, 'msg': 'Not implemented yet in the auth refactor'}
 
+def task_status_delete(context, data_dict):
+    model = context['model']
+    user = context['user']
+
+    authorized =  Authorizer().is_sysadmin(unicode(user))
+    if not authorized:
+        return {'success': False, 'msg': _('User %s not authorized to delete task_status') % str(user)}
+    else:
+        return {'success': True}


--- a/ckan/tests/functional/api/test_action.py	Wed Oct 05 16:29:54 2011 +0100
+++ b/ckan/tests/functional/api/test_action.py	Wed Oct 05 16:48:59 2011 +0100
@@ -623,7 +623,7 @@
             'entity_id': package_created['id'],
             'entity_type': u'package',
             'task_type': u'test_task',
-            'key': u'test_key',
+            'key': u'test_task_status_show',
             'value': u'test_value',
             'state': u'test_state'
         }
@@ -644,3 +644,42 @@
         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)
+
+    def test_25_task_status_delete(self):
+        package = {
+            'name': u'test_task_status_delete',
+            '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_task_status_delete',
+            '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_delete', params=postparams,
+            extra_environ={'Authorization': str(self.sysadmin_user.apikey)},
+        )
+        task_status_delete = json.loads(res.body)
+        assert task_status_delete['success'] == True

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