allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [08/11] allura git commit: [#7832] ticket:731 Delete webhook endpoint
Date Mon, 23 Feb 2015 13:28:03 GMT
[#7832] ticket:731 Delete webhook endpoint


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/63f7e575
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/63f7e575
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/63f7e575

Branch: refs/heads/ib/7832
Commit: 63f7e57520f0d1da2d71f72711ae7a70a79af9d0
Parents: 3bb19e9
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Feb 23 09:58:09 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon Feb 23 09:58:09 2015 +0000

----------------------------------------------------------------------
 Allura/allura/tests/test_webhooks.py | 16 ++++++++++++++++
 Allura/allura/webhooks.py            | 11 +++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/63f7e575/Allura/allura/tests/test_webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py
index ee9cd0b..50a9803 100644
--- a/Allura/allura/tests/test_webhooks.py
+++ b/Allura/allura/tests/test_webhooks.py
@@ -878,3 +878,19 @@ class TestWebhookRestController(TestRestApiBase):
         webhook = M.Webhook.query.get(_id=webhook._id)
         assert_equal(webhook.hook_url, 'http://httpbin.org/post/0')
         assert_equal(webhook.secret, 'secret-0')
+
+    def test_delete_validation(self):
+        url = '{}/repo-push/invalid'.format(self.url)
+        self.api_delete(url, status=404)
+
+    def test_delete(self):
+        assert_equal(M.Webhook.query.find().count(), 3)
+        webhook = self.webhooks[0]
+        url = '{}/repo-push/{}'.format(self.url, webhook._id)
+        msg = 'delete webhook repo-push {} {}'.format(
+            webhook.hook_url, self.git.config.url())
+        with td.audits(msg):
+            r = self.api_delete(url, status=200)
+        dd.assert_equal(r.json, {u'result': u'ok'})
+        assert_equal(M.Webhook.query.find().count(), 2)
+        assert_equal(M.Webhook.query.get(_id=webhook._id), None)

http://git-wip-us.apache.org/repos/asf/allura/blob/63f7e575/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index 6f06602..9b5b41c 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -272,6 +272,8 @@ class WebhookRestController(BaseController):
             raise exc.HTTPNotFound()
         if request.method == 'POST':
             return self._edit(wh, form, **kw)
+        elif request.method == 'DELETE':
+            return self._delete(wh)
         else:
             return {'result': 'ok', 'webhook': wh}
 
@@ -301,6 +303,15 @@ class WebhookRestController(BaseController):
         return {'result': 'ok',
                 'webhook': webhook}
 
+    def _delete(self, webhook):
+        webhook.delete()
+        M.AuditLog.log(
+            'delete webhook %s %s %s',
+            webhook.type,
+            webhook.hook_url,
+            webhook.app_config.url())
+        return {'result': 'ok'}
+
 
 class SendWebhookHelper(object):
     def __init__(self, webhook, payload):


Mime
View raw message