mirror of https://github.com/zulip/zulip.git
outgoing webhooks: Remove process_failure interface method.
This commit is contained in:
parent
fdc9294a6e
commit
fcb889c5c0
|
@ -50,12 +50,6 @@ class OutgoingWebhookServiceInterface(object):
|
|||
# type: (Response, Dict[Text, Any]) -> Optional[str]
|
||||
raise NotImplementedError()
|
||||
|
||||
# Given a failed outgoing webhook REST operation, returns the message to be
|
||||
# sent back to the user (or None if no message should be sent).
|
||||
def process_failure(self, response, event):
|
||||
# type: (Response, Dict[Text, Any]) -> Optional[str]
|
||||
raise NotImplementedError()
|
||||
|
||||
class GenericOutgoingWebhookService(OutgoingWebhookServiceInterface):
|
||||
|
||||
def process_event(self, event):
|
||||
|
@ -80,10 +74,6 @@ class GenericOutgoingWebhookService(OutgoingWebhookServiceInterface):
|
|||
else:
|
||||
return None
|
||||
|
||||
def process_failure(self, response, event):
|
||||
# type: (Response, Dict[Text, Any]) -> Optional[str]
|
||||
return str(response.text)
|
||||
|
||||
class SlackOutgoingWebhookService(OutgoingWebhookServiceInterface):
|
||||
|
||||
def process_event(self, event):
|
||||
|
@ -120,10 +110,6 @@ class SlackOutgoingWebhookService(OutgoingWebhookServiceInterface):
|
|||
else:
|
||||
return None
|
||||
|
||||
def process_failure(self, response, event):
|
||||
# type: (Response, Dict[Text, Any]) -> Optional[str]
|
||||
return str(response.text)
|
||||
|
||||
AVAILABLE_OUTGOING_WEBHOOK_INTERFACES = {
|
||||
GENERIC_INTERFACE: GenericOutgoingWebhookService,
|
||||
SLACK_INTERFACE: SlackOutgoingWebhookService,
|
||||
|
@ -213,9 +199,8 @@ def do_rest_call(rest_operation, request_data, event, service_handler, timeout=N
|
|||
elif str(response.status_code).startswith('5'):
|
||||
request_retry(event, "Internal Server error at third party.")
|
||||
else:
|
||||
response_message = service_handler.process_failure(response, event)
|
||||
if response_message is not None:
|
||||
fail_with_message(event, response_message)
|
||||
failure_message = "Third party responded with %d" % (response.status_code)
|
||||
fail_with_message(event, failure_message)
|
||||
|
||||
except requests.exceptions.Timeout:
|
||||
logging.info("Trigger event %s on %s timed out. Retrying" % (event["command"], event['service_name']))
|
||||
|
|
|
@ -52,13 +52,6 @@ class TestGenericOutgoingWebhookService(ZulipTestCase):
|
|||
success_response = self.handler.process_success(response, self.event)
|
||||
self.assertEqual(success_response, None)
|
||||
|
||||
def test_process_failure(self):
|
||||
# type: () -> None
|
||||
response = mock.Mock(spec=Response)
|
||||
response.text = 'test_content'
|
||||
success_response = self.handler.process_failure(response, self.event)
|
||||
self.assertEqual(success_response, 'test_content')
|
||||
|
||||
mock_service = Service()
|
||||
|
||||
class TestSlackOutgoingWebhookService(ZulipTestCase):
|
||||
|
@ -116,10 +109,3 @@ class TestSlackOutgoingWebhookService(ZulipTestCase):
|
|||
response.text = json.dumps({"text": 'test_content'})
|
||||
success_response = self.handler.process_success(response, self.event)
|
||||
self.assertEqual(success_response, 'test_content')
|
||||
|
||||
def test_process_failure(self):
|
||||
# type: () -> None
|
||||
response = mock.Mock(spec=Response)
|
||||
response.text = 'test_content'
|
||||
success_response = self.handler.process_failure(response, self.event)
|
||||
self.assertEqual(success_response, 'test_content')
|
||||
|
|
|
@ -36,10 +36,6 @@ class MockServiceHandler(OutgoingWebhookServiceInterface):
|
|||
# type: (Response, Dict[Text, Any]) -> Optional[str]
|
||||
return "Success!"
|
||||
|
||||
def process_failure(self, response, event):
|
||||
# type: (Response, Dict[Text, Any]) -> Optional[str]
|
||||
return "Failure!"
|
||||
|
||||
service_handler = MockServiceHandler(None, None, None, None)
|
||||
|
||||
class DoRestCallTests(ZulipTestCase):
|
||||
|
|
Loading…
Reference in New Issue