Exemplo n.º 1
0
    def test_send_webhook_disabled(self):
        from sitevars.notifications_enable import NotificationsEnable
        NotificationsEnable.enable_notifications(False)

        with patch.object(NotificationsEnable,
                          'notifications_enabled',
                          wraps=NotificationsEnable.notifications_enabled
                          ) as mock_check_enabled:
            exit_code = TBANSHelper._send_webhook([], MockNotification())
            mock_check_enabled.assert_called_once()
            self.assertEqual(exit_code, 1)
Exemplo n.º 2
0
    def test_send_webhook_multiple(self):
        clients = [
            MobileClient(parent=ndb.Key(Account, 'user_id'),
                         user_id='user_id',
                         messaging_id='{}'.format(i),
                         client_type=ClientType.WEBHOOK) for i in range(3)
        ]

        batch_response = messaging.BatchResponse([])
        with patch.object(WebhookRequest, 'send',
                          return_value=batch_response) as mock_send:
            exit_code = TBANSHelper._send_webhook(clients, MockNotification())
            self.assertEqual(mock_send.call_count, 3)
            self.assertEqual(exit_code, 0)
Exemplo n.º 3
0
    def test_send_webhook_filter_webhook_clients(self):
        expected = 'client_type_{}'.format(ClientType.WEBHOOK)
        clients = [
            MobileClient(parent=ndb.Key(Account, 'user_id'),
                         user_id='user_id',
                         messaging_id='client_type_{}'.format(client_type),
                         client_type=client_type)
            for client_type in ClientType.names.keys()
        ]

        with patch(
                'models.notifications.requests.webhook_request.WebhookRequest',
                autospec=True) as mock_init:
            exit_code = TBANSHelper._send_webhook(clients, MockNotification())
            mock_init.assert_called_once_with(ANY, expected, ANY)
            self.assertEqual(exit_code, 0)
Exemplo n.º 4
0
    def test_send_webhook_filter_webhook_clients_verified(self):
        clients = [
            MobileClient(parent=ndb.Key(Account, 'user_id'),
                         user_id='user_id',
                         messaging_id='unverified',
                         client_type=ClientType.WEBHOOK,
                         verified=False),
            MobileClient(parent=ndb.Key(Account, 'user_id'),
                         user_id='user_id',
                         messaging_id='verified',
                         client_type=ClientType.WEBHOOK,
                         verified=True)
        ]

        with patch(
                'models.notifications.requests.webhook_request.WebhookRequest',
                autospec=True) as mock_init:
            exit_code = TBANSHelper._send_webhook(clients, MockNotification())
            mock_init.assert_called_once_with(ANY, 'verified', ANY)
            self.assertEqual(exit_code, 0)