def points_dict_to_object(self, dict):

        return PointsCalculationPolicy(
            dict['_PointsCalculationPolicy__win_points'],
            dict['_PointsCalculationPolicy__tie_points'],
            dict['_PointsCalculationPolicy__lose_points'],
            dict['_PointsCalculationPolicy__policy_id'])
    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])
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
Example #4
0
    def create_points_policy(self,
                             win_points,
                             tie_points,
                             lose_points,
                             user_id=""):

        try:
            self.__policy_db.add_point_policy(
                PointsCalculationPolicy(win_points, tie_points, lose_points,
                                        self.__points_policy_id_counter))
            self.update_points_policy_counter()
            Logger.info_log(
                "{}: Created new points calculation policy".format(user_id))
        except Exception as err:
            Logger.error_log("{}:".format(user_id) + str(err))
            raise err
    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)
    def test_points_calculation_policy(self):

        points_policy = PointsCalculationPolicy(3, 0, -3)
        self.assertEqual(points_policy.win_points, 3)
        self.assertEqual(points_policy.tie_points, 0)
        self.assertEqual(points_policy.lose_points, -3)
    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
from Domain.PointsCalculationPolicy import PointsCalculationPolicy
from Domain.GameSchedulePolicy import GameSchedulePolicy
from Domain.TeamBudgetPolicy import TeamBudgetPolicy

user_db = MongoUserDB()
team_db = MongoTeamDB()
league_db = MongoLeagueDB()
policy_db = MongoPolicyDB()
season_db = MongoSeasonDB()
game_db = MongoGameDB()
game_event_db = MongoGameEventDB()

match_cont = MatchController(game_db, user_db, game_event_db, team_db)
team_cont = TeamManagementController(team_db, user_db)
user_con = SignedUserController(user_db)

policy = PointsCalculationPolicy(2, 12, 2, 13)
policy_db.add_point_policy(policy)

# game = game_db.get(1)
# game.remove_event(1)
# game.remove_event(2)
# game.remove_event(3)
# game.remove_event(6)
# game.remove_event(21)
# game.remove_event(22)
# game.remove_event(14)
# game.remove_event(16)
# game.remove_event(17)
# game.remove_event(18)