def test_set_game_schedule_policy(self):

        p = GameSchedulePolicy(1, GameAssigningPoliciesEnum.EQUAL_HOME_AWAY,
                               '', '')
        self.league.game_schedule_policy = p
        self.assertEqual(p, self.league._League__policies['Schedule'])
        self.league.game_schedule_policy = self.gsp
    def test_add_league(self):
        league = League(
            "Euro", Season(2020), PointsCalculationPolicy(3, 0, -3),
            GameSchedulePolicy(1, GameAssigningPoliciesEnum.RANDOM, '', ''),
            TeamBudgetPolicy(1000))

        self.team.add_league(league)
        self.assertEqual(league, self.team._Team__leagues[2020][0])
    def test_game_schedule_policy(self):

        days = ['S', 'M']
        schedule_policy = GameSchedulePolicy(5, 3, days, GameAssigningPoliciesEnum.RANDOM)

        self.assertEqual(schedule_policy.team_games_num, 5)
        self.assertEqual(schedule_policy.games_per_week, 3)
        self.assertEqual(schedule_policy.chosen_days, days)
        self.assertEqual(schedule_policy.team_stadium_assignment_policy, GameAssigningPoliciesEnum.RANDOM)
class TestLeague(TestCase):

    season = Season(2020)
    pcp = PointsCalculationPolicy(3, 0, -3)
    gsp = GameSchedulePolicy(1, GameAssigningPoliciesEnum.RANDOM, '', '')
    tbp = TeamBudgetPolicy(20000)
    league = League("Euro", season, pcp, gsp, tbp)
    """ Testing add_team and remove_team method """
    def test_add_remove_team(self):

        team = Team("Real Madrid")
        self.league.add_team(team)
        self.assertIn(team, self.league._League__teams[team.name])

        self.league.remove_team(team.name)
        self.assertNotIn(team.name, self.league._League__teams.keys())

    """ Testing add_referee and remove_referee method """

    def test_add_remove_referee(self):

        ref = Referee(RefereeQualificationEnum.MAIN, 'Dor123', '12345678',
                      'Dor', datetime(1990, 8, 8), '1.1.1.1', '')
        self.league.add_referee(ref)
        self.assertIn(ref, self.league._League__referees)

        self.league.remove_referee(ref)
        self.assertNotIn(ref, self.league._League__referees)

    """ Testing Getters """

    def test_getters(self):

        self.assertEqual(self.league.name, "Euro")
        self.assertEqual(self.league.season, self.season)
        self.assertEqual(self.league.points_calculation_policy, self.pcp)
        self.assertEqual(self.league.game_schedule_policy, self.gsp)

    """ Testing set_points_calculation_policy method """

    def test_set_points_calculation_policy(self):

        p = PointsCalculationPolicy(1, 0, -1)
        self.league.points_calculation_policy = p
        self.assertEqual(p, self.league._League__policies['Points'])
        self.league.points_calculation_policy = self.pcp

    """ Testing set_game_schedule_policy method """

    def test_set_game_schedule_policy(self):

        p = GameSchedulePolicy(1, GameAssigningPoliciesEnum.EQUAL_HOME_AWAY,
                               '', '')
        self.league.game_schedule_policy = p
        self.assertEqual(p, self.league._League__policies['Schedule'])
        self.league.game_schedule_policy = self.gsp
    def schedule_dict_to_object(self, dict):

        policy_enum_dict = {
            'EQUAL_HOME_AWAY': GameAssigningPoliciesEnum.EQUAL_HOME_AWAY,
            'RANDOM': GameAssigningPoliciesEnum.RANDOM
        }

        stadium_assigning = policy_enum_dict[
            dict['_GameSchedulePolicy__games_stadium_assigning_policy']]

        return GameSchedulePolicy(dict['_GameSchedulePolicy__team_games_num'],
                                  dict['_GameSchedulePolicy__games_per_week'],
                                  stadium_assigning,
                                  dict['_GameSchedulePolicy__policy_id'])
    def test_add_league(self):

        self.assertRaises(TypeError, Season.__init__, year=[])

        league = League(
            "Euro", Season(2020), PointsCalculationPolicy(3, 0, -3),
            GameSchedulePolicy(1, GameAssigningPoliciesEnum.RANDOM, '', ''),
            TeamBudgetPolicy(50000))

        self.season.add_league(league)
        self.assertIn(league, self.season.leagues)
        self.assertRaises(ValueError,
                          self.season.add_leagues,
                          leagues=[league])

        self.season.remove_league(league)
        self.assertNotIn(league, self.season.leagues)
Exemplo n.º 7
0
    def create_game_schedule_policy(self,
                                    team_games_num,
                                    games_per_week,
                                    games_stadium_assigning,
                                    user_id=""):

        try:
            self.__policy_db.add_schedule_policy(
                GameSchedulePolicy(team_games_num, games_per_week,
                                   games_stadium_assigning,
                                   self.__schedule_policy_id_counter))
            self.update_schedule_policy_counter()
            Logger.info_log(
                "{}: Created new game schedule policy".format(user_id))
        except Exception as err:
            Logger.error_log("{}:".format(user_id) + str(err))
            raise err