Ejemplo n.º 1
0
    def test_notify_immunity_awarded_event_msg(self):
        event = events.NotifyImmunityAwardedEvent(
            game_id=_TEST_GAME_ID,
            game_options=self.game_options,
            team=_gamedb.team_from_id(
                id="42a73a78-170e-45ed-a3eb-402fa844afa1")
        )

        self.assertEqual(
            _event_messages_as_json(event.messages(gamedb=_gamedb)),
            json.dumps([
                {
                    "class": "SMSEventMessage",
                    "content": ("\nVIR-US: You have received immunity and cannot be voted out "
                                "tonight!\nNext challenge starts tomorrow {tomorrow} at 12PM EDT.\n").format(
                                    tomorrow=self.game_options.game_schedule.tomorrow_localized_string
                    ),
                    "recipient_phone_numbers": [
                        "331-046-5651",
                        "835-161-1468",
                        "191-221-0517",
                        "114-458-3014",
                        "245-228-6657"
                    ]
                }
            ])
        )
Ejemplo n.º 2
0
    def _run_multi_tribe_council(self, winning_tribe: Tribe,
                                 losing_tribe: Tribe, gamedb: Database,
                                 engine: Engine):
        self._wait_for_tribal_council_start_time()

        # fraction of teams in losing tribe must vote
        non_immune_teams = list()
        for team in gamedb.stream_teams(from_tribe=losing_tribe):
            log_message(message="Found losing team {}.".format(team),
                        game_id=self._game_id)
            immunity_granted = random.random(
            ) < self._options.multi_tribe_team_immunity_likelihood
            if not immunity_granted:
                non_immune_teams.append(team)
            else:
                engine.add_event(
                    events.NotifyImmunityAwardedEvent(
                        game_id=self._game_id,
                        game_options=self._options,
                        team=team))

        # announce winner and tribal council for losing tribe
        gamedb.clear_votes()
        engine.add_event(
            events.NotifyMultiTribeCouncilEvent(game_id=self._game_id,
                                                game_options=self._options,
                                                winning_tribe=winning_tribe,
                                                losing_tribe=losing_tribe))
        self._wait_for_tribal_council_end_time()

        # count votes
        for team in non_immune_teams:
            log_message(
                message="Counting votes for non-immune team {}.".format(team),
                game_id=self._game_id)
            voted_out_player = self._get_voted_out_player(team=team,
                                                          gamedb=gamedb)
            if voted_out_player:
                gamedb.deactivate_player(player=voted_out_player)
                log_message(
                    message="Deactivated player {}.".format(voted_out_player),
                    game_id=self._game_id)
                engine.add_event(
                    events.NotifyPlayerVotedOutEvent(
                        game_id=self._game_id,
                        game_options=self._options,
                        player=voted_out_player))

        # notify all players of what happened at tribal council
        engine.add_event(
            events.NotifyTribalCouncilCompletionEvent(
                game_id=self._game_id, game_options=self._options))
Ejemplo n.º 3
0
    def _run_multi_tribe_council(self, winning_tribe: Tribe, losing_tribe: Tribe, gamedb: Database, engine: Engine):
        non_immune_teams = list()

        for team in gamedb.stream_teams(from_tribe=losing_tribe):
            log_message("Found losing team {}.".format(team))
            immunity_granted = random.random() < self._options.multi_tribe_team_immunity_likelihood
            if not immunity_granted:
                non_immune_teams.append(team)
            else:
                engine.add_event(events.NotifyImmunityAwardedEvent(
                    game_id=self._game_id, game_options=self._options, team=team))

        # announce winner and tribal council for losing tribe
        tribal_council_start_timestamp = _unixtime()
        gamedb.clear_votes()
        engine.add_event(events.NotifyMultiTribeCouncilEvent(game_id=self._game_id, game_options=self._options,
                                                             winning_tribe=winning_tribe, losing_tribe=losing_tribe))

        # wait for votes
        while (((_unixtime() - tribal_council_start_timestamp)
                < self._options.multi_tribe_council_time_sec) and not self._stop.is_set()):
            log_message("Waiting for tribal council to end.")
            time.sleep(self._options.game_wait_sleep_interval_sec)

        # count votes
        for team in non_immune_teams:
            log_message("Counting votes for non-immune team {}.".format(team))
            voted_out_player = self._get_voted_out_player(
                team=team, gamedb=gamedb)
            if voted_out_player:
                gamedb.deactivate_player(player=voted_out_player)
                log_message("Deactivated player {}.".format(voted_out_player))
                engine.add_event(events.NotifyPlayerVotedOutEvent(game_id=self._game_id, game_options=self._options,
                                                                  player=voted_out_player))

        # notify all players of what happened at tribal council
        engine.add_event(events.NotifyTribalCouncilCompletionEvent(
            game_id=self._game_id, game_options=self._options))
Ejemplo n.º 4
0
    events.NotifyFinalTribalCouncilEvent(
        game_id=_TEST_GAME_ID,
        game_options=_TEST_GAME_OPTIONS,
        finalists=[_TEST_PLAYER1, _TEST_PLAYER2]),
    events.NotifyPlayerVotedOutEvent(game_id=_TEST_GAME_ID,
                                     game_options=_TEST_GAME_OPTIONS,
                                     player=_TEST_PLAYER1),
    events.NotifyTribalCouncilCompletionEvent(
        game_id=_TEST_GAME_ID,
        game_options=_TEST_GAME_OPTIONS,
    ),
    events.NotifyWinnerAnnouncementEvent(game_id=_TEST_GAME_ID,
                                         game_options=_TEST_GAME_OPTIONS,
                                         winner=_TEST_PLAYER2),
    events.NotifyImmunityAwardedEvent(game_id=_TEST_GAME_ID,
                                      game_options=_TEST_GAME_OPTIONS,
                                      team=_TEST_TEAM2)
]


class EngineTest(unittest.TestCase):
    def setUp(self):
        self._game_options = GameOptions()
        self._game_options.game_schedule = STV_I18N_TABLE['US']

    @mock.patch('game_engine.twilio.TwilioSMSNotifier.send')
    def test_event_processing(self, send_fn):
        engine = Engine(options=self._game_options,
                        game_id=_TEST_GAME_ID,
                        sqs_config_path=_TEST_AMAZON_SQS_CONFIG_PATH,
                        twilio_config_path=_TEST_TWILIO_SMS_CONFIG_PATH,