Repository: getsentry/sentry

Issue:
[plugin] Regression: Webhook Test Button
Somehow during transfer to the new plugin architecture, the webhook plugin's Test button has disappeared.


Discussion:

Resolving patch:
diff --git a/src/sentry/api/endpoints/project_plugin_details.py b/src/sentry/api/endpoints/project_plugin_details.py
--- a/src/sentry/api/endpoints/project_plugin_details.py
+++ b/src/sentry/api/endpoints/project_plugin_details.py
@@ -1,11 +1,13 @@
 from __future__ import absolute_import
 
+import logging
 import six
 
 from django import forms
 from django.core.urlresolvers import reverse
 from rest_framework import serializers
 from rest_framework.response import Response
+from requests.exceptions import HTTPError
 
 from sentry.exceptions import PluginError, PluginIdentityRequired
 from sentry.plugins import plugins
@@ -44,10 +46,26 @@ def get(self, request, project, plugin_id):
 
     def post(self, request, project, plugin_id):
         """
-        Enable plugin
+        Enable plugin or Test plugin
         """
         plugin = self._get_plugin(plugin_id)
 
+        if request.DATA.get('test') and plugin.is_testable():
+            try:
+                test_results = plugin.test_configuration(project)
+            except Exception as exc:
+                if isinstance(exc, HTTPError):
+                    test_results = '%s\n%s' % (exc, exc.response.text[:256])
+                elif hasattr(exc, 'read') and callable(exc.read):
+                    test_results = '%s\n%s' % (exc, exc.read()[:256])
+                else:
+                    logging.exception('Plugin(%s) raised an error during test',
+                                      plugin_id)
+                    test_results = 'There was an internal error with the Plugin'
+            if not test_results:
+                test_results = 'No errors returned'
+            return Response({'detail': test_results}, status=200)
+
         if not plugin.can_disable:
             return Response({'detail': ERR_ALWAYS_ENABLED}, status=400)
 


Test patch:
diff --git a/tests/sentry/api/endpoints/test_project_plugin_details.py b/tests/sentry/api/endpoints/test_project_plugin_details.py
--- a/tests/sentry/api/endpoints/test_project_plugin_details.py
+++ b/tests/sentry/api/endpoints/test_project_plugin_details.py
@@ -1,8 +1,9 @@
 from __future__ import absolute_import
 
+import mock
 from django.core.urlresolvers import reverse
 
-from sentry.plugins import plugins
+from sentry.plugins import plugins, NotificationPlugin
 from sentry.models import ProjectOption
 from sentry.testutils import APITestCase
 
@@ -67,7 +68,8 @@ def test_simple(self):
 
 
 class EnableProjectPluginTest(APITestCase):
-    def test_simple(self):
+    @mock.patch.object(NotificationPlugin, 'test_configuration', side_effect='test_configuration')
+    def test_simple(self, test_configuration):
         project = self.create_project()
 
         self.login_as(user=self.user)
@@ -89,6 +91,11 @@ def test_simple(self):
             project=project,
         ).value is True
 
+        # Testing the Plugin
+        response = self.client.post(url, {'test': True})
+        test_configuration.assert_called_once_with(project)
+        assert response.status_code == 200, (response.status_code, response.content)
+
 
 class DisableProjectPluginTest(APITestCase):
     def test_simple(self):