def match_score(cls, match, user_id=None):
        event = match.event.get()

        from models.notifications.match_score import MatchScoreNotification
        # Send to Event subscribers
        if NotificationType.MATCH_SCORE in NotificationType.enabled_event_notifications:
            users = [user_id] if user_id else []
            if not users:
                users = Subscription.users_subscribed_to_event(
                    event, NotificationType.MATCH_SCORE)
            if users:
                cls._send(users, MatchScoreNotification(match))

        # Send to Team subscribers
        if NotificationType.MATCH_SCORE in NotificationType.enabled_team_notifications:
            for team_key in match.team_keys:
                users = [user_id] if user_id else []
                if not users:
                    users = Subscription.users_subscribed_to_team(
                        team_key.get(), NotificationType.MATCH_SCORE)
                if users:
                    cls._send(users,
                              MatchScoreNotification(match, team_key.get()))

        # Send to Match subscribers
        if NotificationType.MATCH_SCORE in NotificationType.enabled_match_notifications:
            users = [user_id] if user_id else []
            if not users:
                users = Subscription.users_subscribed_to_match(
                    match, NotificationType.MATCH_SCORE)
            if users:
                cls._send(users, MatchScoreNotification(match))

        # Send UPCOMING_MATCH for the N + 2 match after this one
        if not event.matches:
            return
        from helpers.match_helper import MatchHelper
        next_matches = MatchHelper.upcomingMatches(event.matches, num=2)
        # TODO: Think about if we need special-case handling for replayed matches
        # (I don't think we do because if a match gets replayed at EoD, we'll cancel/reschedule
        # for that match notification. If a match gets replayed back-to-back (which doesn't happen?)
        # sending a second notification is probably fine.
        # If there are not 2 scheduled matches (end of Quals, end of Quarters, etc.) don't send
        if len(next_matches) < 2:
            return

        next_match = next_matches.pop()
        cls.schedule_upcoming_match(next_match, user_id)
Exemple #2
0
 def test_data_payload_team(self):
     team = Team.get_by_id('frc1')
     notification = MatchScoreNotification(self.match, team)
     payload = notification.data_payload
     self.assertEqual(len(payload), 3)
     self.assertEqual(payload['event_key'], self.event.key_name)
     self.assertEqual(payload['match_key'], '{}_qm1'.format(self.event.key_name))
     self.assertEqual(payload['team_key'], 'frc1')
 def test_data_payload_team(self):
     team = Team.get_by_id('frc1')
     notification = MatchScoreNotification(self.match, team)
     payload = notification.data_payload
     self.assertEqual(len(payload), 3)
     self.assertEqual(payload['event_key'], '2020testpresent')
     self.assertEqual(payload['match_key'], '2020testpresent_qm1')
     self.assertEqual(payload['team_key'], 'frc1')
Exemple #4
0
 def test_webhook_message_data_team(self):
     team = Team.get_by_id('frc1')
     notification = MatchScoreNotification(self.match, team)
     payload = notification.webhook_message_data
     self.assertEqual(len(payload), 4)
     self.assertEqual(payload['event_key'], self.event.key_name)
     self.assertEqual(payload['event_name'], 'Present Test Event')
     self.assertEqual(payload['team_key'], 'frc1')
     self.assertIsNotNone(payload['match'])
Exemple #5
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()  # Prevent data from leaking between tests

        self.testbed.init_taskqueue_stub(root_path=".")

        for team_number in range(6):
            Team(id="frc%s" % team_number,
                 team_number=team_number).put()

        self.event = EventTestCreator.createPresentEvent()
        self.match = self.event.matches[0]

        self.notification = MatchScoreNotification(self.match)
Exemple #6
0
 def test_fcm_notification_team(self):
     team = Team.get_by_id('frc1')
     notification = MatchScoreNotification(self.match, team)
     self.assertEqual(notification.fcm_notification.title, 'Team 1 TESTPRESENT Q1 Results')
Exemple #7
0
 def test_type(self):
     self.assertEqual(MatchScoreNotification._type(), NotificationType.MATCH_SCORE)