Exemple #1
0
 def test_clients_empty(self):
     abc = MobileClient(
         parent=ndb.Key(Account, 'abc'),
         user_id='abc',
         messaging_id='token',
         client_type=ClientType.OS_IOS,
         device_uuid='uuid',
         display_name='Phone'
     )
     abc.put()
     unverified = MobileClient(
         parent=ndb.Key(Account, 'efg'),
         user_id='efg',
         messaging_id='token',
         client_type=ClientType.OS_IOS,
         device_uuid='uuid',
         display_name='Phone',
         verified=False
     )
     unverified.put()
     # Test empty users returns empty
     self.assertEqual(MobileClient.clients(users=[]), [])
     # Test empty client types return empty
     self.assertEqual(MobileClient.clients(users=['abc'], client_types=[]), [])
     # Test empty users and client types returns empty
     self.assertEqual(MobileClient.clients(users=[], client_types=[]), [])
     # Test client type + users does not return empty
     self.assertEqual(MobileClient.clients(users=['abc']), [abc])
     # Test fetching for only verified
     self.assertEqual(MobileClient.clients(users=['efg']), [])
Exemple #2
0
    def test_clients(self):
        user_id_one = 'user_id_one'
        token_one = 'token1'
        token_two = 'token2'

        user_id_two = 'user_id_two'
        token_three = 'token3'

        user_id_three = 'user_id_three'

        for (user_id, tokens) in [(user_id_one, [token_one, token_two]), (user_id_two, [token_three])]:
            clients = [MobileClient(
                        parent=ndb.Key(Account, user_id),
                        user_id=user_id,
                        messaging_id=token,
                        client_type=ClientType.OS_IOS,
                        device_uuid=token[::-1],
                        display_name='Phone') for token in tokens]
            for client in clients:
                client.put()

        self.assertEqual([client.messaging_id for client in MobileClient.clients([user_id_one])], [token_one, token_two])
        self.assertEqual([client.messaging_id for client in MobileClient.clients([user_id_two])], [token_three])
        self.assertEqual([client.messaging_id for client in MobileClient.clients([user_id_one, user_id_two])], [token_one, token_two, token_three])
        self.assertEqual([client.messaging_id for client in MobileClient.clients([user_id_three])], [])
    def _send(cls, users, notification):
        # Send to FCM clients
        fcm_clients = MobileClient.clients(users, client_types=ClientType.FCM_CLIENTS)
        if fcm_clients:
            cls._defer_fcm(fcm_clients, notification)

        # Send to webhooks
        webhook_clients = MobileClient.clients(users, client_types=[ClientType.WEBHOOK])
        if webhook_clients:
            cls._defer_webhook(webhook_clients, notification)
Exemple #4
0
    def test_clients_type(self):
        clients = [MobileClient(
                    parent=ndb.Key(Account, 'user_id'),
                    user_id='user_id',
                    messaging_id='messaging_id_{}'.format(client_type),
                    client_type=client_type) for client_type in ClientType.names.keys()]
        for client in clients:
            client.put()

        self.assertEqual([client.messaging_id for client in MobileClient.clients(['user_id'], client_types=[ClientType.OS_ANDROID])], ['messaging_id_0'])
        self.assertEqual([client.messaging_id for client in MobileClient.clients(['user_id'], client_types=ClientType.FCM_CLIENTS)], ['messaging_id_1', 'messaging_id_3'])
        self.assertEqual([client.messaging_id for client in MobileClient.clients(['user_id'], client_types=[ClientType.WEBHOOK])], ['messaging_id_2'])
Exemple #5
0
 def test_clients_multiple(self):
     abc = MobileClient(
         parent=ndb.Key(Account, 'abc'),
         user_id='abc',
         messaging_id='token',
         client_type=ClientType.OS_IOS,
         device_uuid='uuid',
         display_name='Phone'
     )
     abc.put()
     efg = MobileClient(
         parent=ndb.Key(Account, 'efg'),
         user_id='efg',
         messaging_id='token',
         client_type=ClientType.OS_IOS,
         device_uuid='uuid',
         display_name='Phone'
     )
     efg.put()
     self.assertEqual(MobileClient.clients(['abc', 'efg']), [abc, efg])
Exemple #6
0
    def post(self):
        self._require_admin()

        user_id = self.user_bundle.account.key.id()

        notification_type = self.request.get('type')
        if notification_type == "awards":
            event_key = self.request.get('event_key')
            event = Event.get_by_id(event_key)
            if not event:
                self.template_values.update(
                    {'error': 'No event for key {}'.format(event_key)})
                return self.redirect('/admin/tbans')

            TBANSHelper.awards(event, user_id)
        elif notification_type == "ping":
            clients = MobileClient.clients([user_id])
            for client in clients:
                TBANSHelper.ping(client)

        return self.redirect('/admin/tbans')
    def post(self):
        self._require_admin()

        user_id = self.user_bundle.account.key.id()

        notification_type = self.request.get('type')
        if notification_type == "alliance_selection":
            event_key = self.request.get('event_key')
            event = Event.get_by_id(event_key)
            if not event:
                self.template_values.update({
                    'error': 'No event for key {}'.format(event_key)
                })
                return self.redirect('/admin/tbans')

            TBANSHelper.alliance_selection(event, user_id)
        elif notification_type == "awards":
            event_key = self.request.get('event_key')
            event = Event.get_by_id(event_key)
            if not event:
                self.template_values.update({
                    'error': 'No event for key {}'.format(event_key)
                })
                return self.redirect('/admin/tbans')

            TBANSHelper.awards(event, user_id)
        elif notification_type == "event_level":
            match_key = self.request.get('match_key')
            match = Match.get_by_id(match_key)
            if not match:
                self.template_values.update({
                    'error': 'No match for key {}'.format(match_key)
                })
                return self.redirect('/admin/tbans')

            TBANSHelper.event_level(match, user_id)
        elif notification_type == "event_schedule":
            event_key = self.request.get('event_key')
            event = Event.get_by_id(event_key)
            if not event:
                self.template_values.update({
                    'error': 'No event for key {}'.format(event_key)
                })
                return self.redirect('/admin/tbans')

            TBANSHelper.event_schedule(event, user_id)
        elif notification_type == "match_score":
            match_key = self.request.get('match_key')
            match = Match.get_by_id(match_key)
            if not match:
                self.template_values.update({
                    'error': 'No match for key {}'.format(match_key)
                })
                return self.redirect('/admin/tbans')

            TBANSHelper.match_score(match, user_id)
        elif notification_type == "match_upcoming":
            match_key = self.request.get('match_key')
            match = Match.get_by_id(match_key)
            if not match:
                self.template_values.update({
                    'error': 'No match for key {}'.format(match_key)
                })
                return self.redirect('/admin/tbans')

            TBANSHelper.match_upcoming(match, user_id)
        elif notification_type == "match_video":
            match_key = self.request.get('match_key')
            match = Match.get_by_id(match_key)
            if not match:
                self.template_values.update({
                    'error': 'No match for key {}'.format(match_key)
                })
                return self.redirect('/admin/tbans')

            TBANSHelper.match_video(match, user_id)
        elif notification_type == "ping":
            clients = MobileClient.clients([user_id])
            for client in clients:
                TBANSHelper.ping(client)

        return self.redirect('/admin/tbans')