def match_video(cls, match, user_id=None): from models.notifications.match_video import MatchVideoNotification # Send to Event subscribers if NotificationType.MATCH_VIDEO in NotificationType.enabled_event_notifications: users = [user_id] if user_id else [] if not users: users = Subscription.users_subscribed_to_event( match.event.get(), NotificationType.MATCH_VIDEO) if users: cls._send(users, MatchVideoNotification(match)) # Send to Team subscribers if NotificationType.MATCH_VIDEO 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_VIDEO) if users: cls._send(users, MatchVideoNotification(match, team_key.get())) # Send to Match subscribers if NotificationType.MATCH_VIDEO in NotificationType.enabled_match_notifications: users = [user_id] if user_id else [] if not users: users = Subscription.users_subscribed_to_match( match, NotificationType.MATCH_VIDEO) if users: cls._send(users, MatchVideoNotification(match))
def test_data_payload_team(self): team = Team.get_by_id('frc1') notification = MatchVideoNotification(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')
def test_data_payload_team(self): team = Team.get_by_id('frc1') notification = MatchVideoNotification(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_webhook_message_data_team(self): team = Team.get_by_id('frc1') notification = MatchVideoNotification(self.match, team) payload = notification.webhook_message_data self.assertEqual(len(payload), 4) self.assertEqual(payload['event_key'], '2020testpresent') self.assertEqual(payload['event_name'], 'Present Test Event') self.assertEqual(payload['team_key'], 'frc1') self.assertIsNotNone(payload['match'])
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 = MatchVideoNotification(self.match)
def test_fcm_notification_team(self): team = Team.get_by_id('frc1') notification = MatchVideoNotification(self.match, team) self.assertEqual(notification.fcm_notification.title, 'Team 1 Match Video') self.assertEqual(notification.fcm_notification.body, 'Video for TESTPRESENT Quals 1 featuring Team 1 has been posted.')
def test_type(self): self.assertEqual(MatchVideoNotification._type(), NotificationType.MATCH_VIDEO)