def test_fcm_notification_team_winner(self): self.winner_award.team_list = [self.team.key] self.winner_award.put() notification = AwardsNotification(self.event, self.team) self.assertIsNotNone(notification.fcm_notification) self.assertEqual(notification.fcm_notification.title, 'Team 7332 Awards') self.assertEqual(notification.fcm_notification.body, 'Team 7332 is the District Event Winner at the 2020 Kettering University #1 District.')
def test_fcm_notification_team(self): self.award.team_list = [self.team.key] self.award.put() notification = AwardsNotification(self.event, self.team) self.assertIsNotNone(notification.fcm_notification) self.assertEqual(notification.fcm_notification.title, 'Team 7332 Awards') self.assertEqual(notification.fcm_notification.body, 'Team 7332 won the Industrial Design Award sponsored by General Motors at the 2020 Kettering University #1 District.')
def awards(cls, event, user_id=None): if user_id: users = [user_id] else: users = Subscription.users_subscribed_to_event( event, NotificationType.AWARDS) from models.notifications.awards import AwardsNotification # Send to FCM/webhooks cls._send(users, AwardsNotification(event))
def test_fcm_notification_team_finalist(self): self.winner_award.award_type_enum=AwardType.WINNER self.winner_award.name_str='District Event Finalist' self.winner_award.team_list = [self.team.key] self.winner_award.put() notification = AwardsNotification(self.event, self.team) self.assertIsNotNone(notification.fcm_notification) self.assertEqual(notification.fcm_notification.title, 'Team 7332 Awards') self.assertEqual(notification.fcm_notification.body, 'Team 7332 is the District Event Finalist at the 2020 Kettering University #1 District.')
def test_webhook_message_data(self): self.award.put() self.winner_award.put() notification = AwardsNotification(self.event) payload = notification.webhook_message_data self.assertEqual(len(payload), 3) self.assertEqual(payload['event_key'], '2020miket') self.assertEqual(payload['event_name'], 'FIM District Kettering University Event #1') self.assertIsNotNone(payload['awards']) self.assertEqual(len(payload['awards']), 2)
def test_webhook_message_data_team(self): self.award.team_list = [self.team.key] self.award.put() notification = AwardsNotification(self.event, self.team) payload = notification.webhook_message_data self.assertEqual(len(payload), 4) self.assertEqual(payload['event_key'], '2020miket') self.assertEqual(payload['team_key'], 'frc7332') self.assertEqual(payload['event_name'], 'FIM District Kettering University Event #1') self.assertIsNotNone(payload['awards']) self.assertEqual(len(payload['awards']), 1)
def awards(cls, event, user_id=None): from models.notifications.awards import AwardsNotification # Send to Event subscribers if NotificationType.AWARDS in NotificationType.enabled_event_notifications: users = [user_id] if user_id else [] if not users: users = Subscription.users_subscribed_to_event(event, NotificationType.AWARDS) if users: cls._send(users, AwardsNotification(event)) # Send to Team subscribers if NotificationType.AWARDS in NotificationType.enabled_team_notifications: # Map all Teams to their Awards so we can populate our Awards notification with more specific info team_awards = event.team_awards() for team_key in team_awards.keys(): team = team_key.get() users = [user_id] if user_id else [] if not users: users = Subscription.users_subscribed_to_team(team, NotificationType.AWARDS) if users: cls._send(users, AwardsNotification(event, team))
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() self.testbed.init_taskqueue_stub(root_path=".") for team_number in range(7): Team(id="frc%s" % team_number, team_number=team_number).put() self.event = EventTestCreator.createPresentEvent() self.notification = AwardsNotification(self.event)
def test_fcm_notification_event(self): notification = AwardsNotification(self.event) self.assertIsNotNone(notification.fcm_notification) self.assertEqual(notification.fcm_notification.title, 'MIKET Awards') self.assertEqual(notification.fcm_notification.body, '2020 Kettering University #1 District awards have been posted.')
def test_type(self): notification = AwardsNotification(self.event) self.assertEqual(AwardsNotification._type(), NotificationType.AWARDS)
def test_data_payload_team(self): notification = AwardsNotification(self.event, self.team) payload = notification.data_payload self.assertEqual(len(payload), 2) self.assertEqual(payload['event_key'], '2020miket') self.assertEqual(payload['team_key'], 'frc7332')
def test_data_payload(self): notification = AwardsNotification(self.event) # No `event_name` payload = notification.data_payload self.assertEqual(len(payload), 1) self.assertEqual(payload['event_key'], '2020miket')
def test_type(self): self.assertEqual(AwardsNotification._type(), NotificationType.AWARDS)