Пример #1
0
    def match_upcoming(cls, match, user_id=None):
        from models.notifications.match_upcoming import MatchUpcomingNotification
        # Send to Event subscribers
        if NotificationType.UPCOMING_MATCH 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.UPCOMING_MATCH)
            if users:
                cls._send(users, MatchUpcomingNotification(match))

        # Send to Team subscribers
        if NotificationType.UPCOMING_MATCH 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.UPCOMING_MATCH)
                if users:
                    cls._send(users,
                              MatchUpcomingNotification(match, team_key.get()))

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

        # Send LEVEL_STARTING for the first match of a new type
        if match.set_number == 1 and match.match_number == 1:
            cls.event_level(match, user_id)
    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.match = self.event.matches[0]

        self.notification = MatchUpcomingNotification(self.match)
 def test_type(self):
     self.assertEqual(MatchUpcomingNotification._type(), NotificationType.UPCOMING_MATCH)