예제 #1
0
    def verify_webhook(url, secret):
        """ Immediately dispatch a Verification to a webhook """
        from models.notifications.verification import VerificationNotification
        notification = VerificationNotification(url, secret)

        from models.notifications.requests.webhook_request import WebhookRequest
        webhook_request = WebhookRequest(notification, url, secret)
        logging.info('Verification - {}'.format(str(webhook_request)))

        webhook_request.send()
        logging.info('Verification Key - {}'.format(notification.verification_key))

        return notification.verification_key
예제 #2
0
    def _send_webhook(cls, clients, notification):
        # Only send to webhooks if notifications are enabled
        if not cls._notifications_enabled():
            return 1

        # Make sure we're only sending to webhook clients
        clients = [client for client in clients if client.client_type == ClientType.WEBHOOK]

        from models.notifications.requests.webhook_request import WebhookRequest
        for client in clients:
            webhook_request = WebhookRequest(notification, client.messaging_id, client.secret)
            logging.info(str(webhook_request))

            webhook_request.send()

        return 0
    def test_send_headers(self):
        message = WebhookRequest(
            MockNotification(webhook_message_data={'data': 'value'}),
            'https://www.thebluealliance.com', 'secret')

        with patch.object(urllib2, 'urlopen') as mock_urlopen:
            message.send()
        mock_urlopen.assert_called_once()
        request = mock_urlopen.call_args_list[0][0][0]
        self.assertIsNotNone(request)
        self.assertEqual(
            request.headers, {
                'X-tba-checksum': 'dbecd85ae53d221c387647085912d2107fa04cd5',
                'Content-type': 'application/json; charset="utf-8"',
                'X-tba-hmac':
                'fb2b61d55884a648b35801688754924778b3e71ea2bf8f5effb0f3ffecb5c940',
                'X-tba-version': '1'
            })
    def test_send(self):
        message = WebhookRequest(
            MockNotification(webhook_message_data={'data': 'value'}),
            'https://www.thebluealliance.com', 'secret')

        with patch.object(urllib2, 'urlopen') as mock_urlopen, patch.object(
                message, 'defer_track_notification') as mock_track:
            success = message.send()
        mock_urlopen.assert_called_once()
        mock_track.assert_called_once_with(1)
        self.assertTrue(success)
예제 #5
0
    def _ping_webhook(client):
        from models.notifications.ping import PingNotification
        notification = PingNotification()

        from models.notifications.requests.webhook_request import WebhookRequest
        webhook_request = WebhookRequest(notification, client.messaging_id, client.secret)
        logging.info('Ping - {}'.format(str(webhook_request)))

        success = webhook_request.send()
        logging.info('Ping Sent')

        return success
    def test_send_error_other(self):
        message = WebhookRequest(
            MockNotification(webhook_message_data={'data': 'value'}),
            'https://www.thebluealliance.com', 'secret')

        error_mock = Mock()
        error_mock.side_effect = Exception('testing')

        with patch.object(urllib2, 'urlopen',
                          error_mock) as mock_urlopen, patch.object(
                              message,
                              'defer_track_notification') as mock_track:
            success = message.send()
        mock_urlopen.assert_called_once()
        mock_track.assert_not_called()
        self.assertTrue(success)
    def test_send_fail_deadline_error(self):
        message = WebhookRequest(
            MockNotification(webhook_message_data={'data': 'value'}),
            'https://www.thebluealliance.com', 'secret')

        error_mock = Mock()
        error_mock.side_effect = Exception(
            'Deadline exceeded while waiting for HTTP response from URL: https://thebluealliance.com'
        )

        with patch.object(urllib2, 'urlopen',
                          error_mock) as mock_urlopen, patch.object(
                              message,
                              'defer_track_notification') as mock_track:
            success = message.send()
        mock_urlopen.assert_called_once()
        mock_track.assert_not_called()
        self.assertTrue(success)