def test_send_empty(self):
     notification = MockNotification()
     with patch.object(TBANSHelper, '_defer_fcm') as mock_fcm, patch.object(
             TBANSHelper, '_defer_webhook') as mock_webhook:
         TBANSHelper._send([], notification)
         mock_fcm.assert_not_called()
         mock_webhook.assert_not_called()
    def test_send(self):
        expected = [
            'client_type_{}'.format(client_type)
            for client_type in ClientType.FCM_CLIENTS
        ]
        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()
        ]
        # Insert an unverified webhook, just to test
        unverified = MobileClient(parent=ndb.Key(Account, 'user_id'),
                                  user_id='user_id',
                                  messaging_id='client_type_2',
                                  client_type=ClientType.WEBHOOK,
                                  verified=False)
        unverified.put()
        for c in clients:
            c.put()

        expected_fcm = [
            c for c in clients if c.client_type in ClientType.FCM_CLIENTS
        ]
        expected_webhook = [
            c for c in clients if c.client_type == ClientType.WEBHOOK
        ]

        notification = MockNotification()
        with patch.object(TBANSHelper, '_defer_fcm') as mock_fcm, patch.object(
                TBANSHelper, '_defer_webhook') as mock_webhook:
            TBANSHelper._send(['user_id'], notification)
            mock_fcm.assert_called_once_with(expected_fcm, notification)
            mock_webhook.assert_called_once_with(expected_webhook,
                                                 notification)