def test_show_games_by_referee(self):
     d1 = datetime.datetime(2020, 4, 23)
     d2 = datetime.datetime(2001, 4, 23)
     ref = Referee(RefereeQualificationEnum.MAIN, "name_u1", "1234", "ro", d1, "0.0.0.5", 23)
     game1 = Game(Team("Real Madrid"), Team("Barcelona"), d2, "Camp Nou")
     game2 = Game(Team("Real Madrid2"), Team("Barcelona2"), d1, "Camp Nou2")
     game1.add_referee(ref)
     ref.add_game(game1)
     self.assertIn(game1, ref.show_games_by_referee())
     self.assertNotIn(game2, ref.show_games_by_referee())
 def test_add_event(self):
     d1 = datetime.datetime(2020, 4, 23)
     d2 = datetime.datetime(2001, 4, 23)
     ref = Referee(RefereeQualificationEnum.MAIN, "name_u1", "1234", "ro", d1, "0.0.0.5", 23)
     game1 = Game(Team("Real Madrid"), Team("Barcelona"), d2, "Camp Nou")
     game1.add_referee(ref)
     event1 = GameEvent(game1, ref, EventTypeEnum.GOAL, "Start!", d1, 22)
     self.assertIn(event1, ref.events)
     ref.remove_event(event1)
     self.assertNotIn(event1, ref.events)
Пример #3
0
    def add_game(self,
                 home_team_name,
                 away_team_name,
                 match_time,
                 field,
                 main_referee_id,
                 referees=[],
                 user_id=""):
        try:
            home_team = self.__team_DB.get(home_team_name)
            away_team = self.__team_DB.get(away_team_name)
            # Checking for collision

            self.collision_game_check(home_team, match_time)
            self.collision_game_check(away_team, match_time)

            game = Game(self.__game_id_counter, home_team.name, away_team.name,
                        match_time, field)

            home_team.add_game(game.game_id)
            away_team.add_game(game.game_id)

            for referee_id in referees:
                referee = self.__user_DB.get_signed_user(referee_id)
                game.add_referee(referee.user_id)
                referee.add_game(game.game_id)
                self.__user_DB.update_signed_user(referee)
            main_referee = self.__user_DB.get_signed_user(main_referee_id)
            game.main_referee = main_referee.user_id
            main_referee.add_game(game.game_id)

            self.__game_DB.add(game)
            self.update_game_counter()
            self.__team_DB.update(home_team)
            self.__team_DB.update(away_team)
            self.__user_DB.update_signed_user(main_referee)

            Logger.info_log("{0}:".format(user_id) +
                            "Created new game between home:{0} and away:{1} ".
                            format(home_team.name, away_team.name))
        except Exception as err:
            Logger.error_log("{0}:".format(user_id) + err.__str__())
            raise err