def send_award_update(cls, event): users = PushHelper.get_users_subscribed_to_event( event, NotificationType.AWARDS) keys = PushHelper.get_client_ids_for_users(users) notification = AwardsUpdatedNotification(event) notification.send(keys)
def send_award_update(cls, event): users = Subscription.users_subscribed_to_event(event, NotificationType.AWARDS) keys = PushHelper.get_client_ids_for_users( users, os_types=[ClientType.OS_ANDROID]) notification = AwardsUpdatedNotification(event) notification.send(keys)
def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() 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 = AwardsUpdatedNotification(self.event)
class TestAllianceNotification(unittest2.TestCase): def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() 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 = AwardsUpdatedNotification(self.event) def tearDown(self): self.testbed.deactivate() def test_build(self): expected = {} expected['message_type'] = NotificationType.type_names[ NotificationType.AWARDS] expected['message_data'] = {} expected['message_data']['event_name'] = self.event.name expected['message_data']['event_key'] = self.event.key_name expected['message_data']['awards'] = [ ModelToDict.awardConverter(award) for award in AwardHelper.organizeAwards(self.event.awards) ] data = self.notification._build_dict() self.assertEqual(expected, data)
class TestAwardsNotification(unittest2.TestCase): 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(7): Team(id="frc%s" % team_number, team_number=team_number).put() self.event = EventTestCreator.createPresentEvent() self.notification = AwardsUpdatedNotification(self.event) def tearDown(self): self.testbed.deactivate() def test_build(self): expected = {} expected['notification_type'] = NotificationType.type_names[NotificationType.AWARDS] expected['message_data'] = {} expected['message_data']['event_name'] = self.event.name expected['message_data']['event_key'] = self.event.key_name expected['message_data']['awards'] = [ModelToDict.awardConverter(award) for award in AwardHelper.organizeAwards(self.event.awards)] data = self.notification._build_dict() self.assertEqual(expected, data)
def get(self, type): self._require_registration('/account/') user_id = self.user_bundle.account.key.id() logging.info("Sending for {}".format(type)) try: type = int(type) except ValueError: # Not passed a valid int, just stop here logging.info("Invalid number passed") self.redirect('/apidocs/webhooks') return event = Event.get_by_id('2014necmp') match = Match.get_by_id('2014necmp_f1m1') district = District.get_by_id('2014ne') if type == NotificationType.UPCOMING_MATCH: notification = UpcomingMatchNotification(match, event) elif type == NotificationType.MATCH_SCORE: notification = MatchScoreNotification(match) elif type == NotificationType.LEVEL_STARTING: notification = CompLevelStartingNotification(match, event) elif type == NotificationType.ALLIANCE_SELECTION: notification = AllianceSelectionNotification(event) elif type == NotificationType.AWARDS: notification = AwardsUpdatedNotification(event) elif type == NotificationType.MEDIA_POSTED: # Not implemented yet pass elif type == NotificationType.DISTRICT_POINTS_UPDATED: notification = DistrictPointsUpdatedNotification(district) elif type == NotificationType.SCHEDULE_UPDATED: notification = ScheduleUpdatedNotification(event, match) elif type == NotificationType.FINAL_RESULTS: # Not implemented yet pass elif type == NotificationType.MATCH_VIDEO: notification = MatchVideoNotification(match) elif type == NotificationType.EVENT_MATCH_VIDEO: notification = EventMatchVideoNotification(match) else: # Not passed a valid int, return self.redirect('/apidocs/webhooks') return keys = PushHelper.get_client_ids_for_users([user_id]) logging.info("Keys: {}".format(keys)) if notification: # This page should not push notifications to the firebase queue # Nor should its notifications be tracked in analytics notification.send(keys, push_firebase=False, track_call=False) self.redirect('/apidocs/webhooks')
def send_award_update(cls, event): users = PushHelper.get_users_subscribed_to_event(event, NotificationType.AWARDS) keys = PushHelper.get_client_ids_for_users(users) notification = AwardsUpdatedNotification(event) notification.send(keys)
def post(self, type): self._require_registration('/account/') event_key = self.request.get('event_key') match_key = self.request.get('match_key') district_key = self.request.get('district_key') user_id = self.user_bundle.account.key.id() logging.info("Sending for {}".format(type)) try: type = int(type) except ValueError: # Not passed a valid int, just stop here logging.info("Invalid number passed") return event = None if type != NotificationType.DISTRICT_POINTS_UPDATED: if event_key == "": logging.info("No event key") self.response.out.write("No event key specified!") return event = Event.get_by_id(event_key) if event is None: logging.info("Invalid event key passed") self.response.out.write("Invalid event key!") return if type == NotificationType.UPCOMING_MATCH: if match_key == "": logging.info("No match key") self.response.out.write("No match key specified!") return match = Match.get_by_id(match_key) if match is None: logging.info("Invalid match key passed") self.response.out.write("Invalid match key!") return notification = UpcomingMatchNotification(match, event) elif type == NotificationType.MATCH_SCORE: if match_key == "": logging.info("No match key") self.response.out.write("No match key specified!") return match = Match.get_by_id(match_key) if match is None: logging.info("Invalid match key passed") self.response.out.write("Invalid match key!") return notification = MatchScoreNotification(match) elif type == NotificationType.LEVEL_STARTING: if match_key == "": logging.info("No match key") self.response.out.write("No match key specified!") return match = Match.get_by_id(match_key) if match is None: logging.info("Invalid match key passed") self.response.out.write("Invalid match key!") return notification = CompLevelStartingNotification(match, event) elif type == NotificationType.ALLIANCE_SELECTION: notification = AllianceSelectionNotification(event) elif type == NotificationType.AWARDS: notification = AwardsUpdatedNotification(event) elif type == NotificationType.MEDIA_POSTED: # Not implemented yet pass elif type == NotificationType.DISTRICT_POINTS_UPDATED: if district_key == "": logging.info("No district key") self.response.out.write("No district key specified!") return district = District.get_by_id(district_key) if district is None: logging.info("Invalid district key passed") self.response.out.write("Invalid district key!") return notification = DistrictPointsUpdatedNotification(district) elif type == NotificationType.SCHEDULE_UPDATED: if match_key == "": logging.info("No match key") self.response.out.write("No match key specified!") return match = Match.get_by_id(match_key) if match is None: logging.info("Invalid match key passed") self.response.out.write("Invalid match key!") return notification = ScheduleUpdatedNotification(event, match) elif type == NotificationType.FINAL_RESULTS: # Not implemented yet pass elif type == NotificationType.MATCH_VIDEO: if match_key == "": logging.info("No match key") self.response.out.write("No match key specified!") return match = Match.get_by_id(match_key) if match is None: logging.info("Invalid match key passed") self.response.out.write("Invalid match key!") return notification = MatchVideoNotification(match) elif type == NotificationType.EVENT_MATCH_VIDEO: if match_key == "": logging.info("No match key") self.response.out.write("No match key specified!") return match = Match.get_by_id(match_key) if match is None: logging.info("Invalid match key passed") self.response.out.write("Invalid match key!") return notification = EventMatchVideoNotification(match) else: # Not passed a valid int, return return keys = PushHelper.get_client_ids_for_users([user_id]) logging.info("Keys: {}".format(keys)) if notification: # This page should not push notifications to the firebase queue # Nor should its notifications be tracked in analytics notification.send(keys, push_firebase=False, track_call=False) self.response.out.write("ok")