def test_add_game(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)
     game = Game(Team("Real Madrid"), Team("Barcelona"), d2, "Camp Nou")
     ref.add_game(game)
     self.assertIn(game, ref.referee_in_games)
class TestNotifications(TestCase):
    not_cont = NotificationController()
    fan1 = Fan("user1", "123", "nameOne", datetime(1993, 1, 1), "1.1.1.1", "1")
    fan2 = Fan("user2", "123", "nameTwo", datetime(1993, 1, 1), "1.1.1.1", "2")
    fan3 = Fan("user3", "123", "nameThree", datetime(1993, 1, 1), "1.1.1.1", "3")
    team1 = Team("team1")
    team2 = Team("team2")
    game1 = Game(team1, team2, datetime.today(), "field1")
    game2 = Game(team1, team2, datetime.today(), "field2")
    referee1 = Referee(RefereeQualificationEnum.MAIN, "user4", "123", "userFour", datetime.today(), "1", "4")
    referee2 = Referee(RefereeQualificationEnum.MAIN, "user5", "123", "userFive", datetime.today(), "1", "5")

    not_cont.add_fan_follower_to_game(fan1, game1)
    not_cont.add_fan_follower_to_game(fan2, game1)
    not_cont.add_fan_follower_to_game(fan2, game2)

    game1.add_referee(referee1)
    game2.add_referee(referee2)
    game_event1 = GameEvent(game1, referee1, EventTypeEnum.YELLOW_CARD, "desc", datetime.today(), 5)
    game_event2 = GameEvent(game2, referee2, EventTypeEnum.GOAL, "desc", datetime.today(), 5)

    def test_add_follower(self):
        self.assertEqual(len(self.fan1.notifications), 2)
        self.assertEqual(len(self.fan2.notifications), 4)
        self.assertEqual(len(self.fan3.notifications), 0)

    def test_remove_follower(self):
        self.not_cont.remove_fan_follower_from_game(self.fan2, self.game1)
        self.game1.remove_referee(self.referee1)
        self.assertEqual(len(self.fan1.notifications), 3)
        self.assertEqual(len(self.fan2.notifications), 4)
        self.assertEqual(len(self.fan3.notifications), 0)
 def test_game_over(self):
     g = Game(self.team, Team("Barcelona"), date(2020, 7, 7), self.field)
     g_error = Game(self.team, Team("RealMadrid"), date(2020, 7, 7),
                    self.field)
     self.team.add_game(g)
     self.team.game_over(g)
     self.assertIn(g, self.team.past_games)
     self.assertNotIn(g, self.team.upcoming_games)
     self.assertRaises(ValueError, self.team.game_over, g_error)
 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)
Пример #6
0
    def setUp(self):

        self.organization = UnionOrganization()
        self.user1 = UnionRepresentor('user_name', '1234', 'Dor',
                                      datetime.today(), '1.1.1.1', 1, 5000)
        self.user2 = UnionRepresentor('user_name', '1234', 'Shahar',
                                      datetime.today(), '1.1.1.1', 1, 5000)
        self.team1 = Team('team1')
        self.team2 = Team('Team2')
        self.team3 = Team('Team3')
    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())
class TestTeamDB(TestCase):
    db = TeamDB()
    team = Team("Real Madrid")
    team = Team("Barca")

    def test_add(self):
        self.db.add(self.team)
        self.assertEqual(1, self.db.teams.__len__())
        self.assertRaises(ValueError, self.db.add, self.team)

    def test_delete(self):
        self.db.add(self.team)
        self.assertEqual(1, self.db.teams.__len__())
        self.db.delete("Barca")
        self.assertEqual(0, self.db.teams.__len__())
        self.assertRaises(ValueError, self.db.delete, "Barca")

    def test_get(self):
        self.db.add(self.team)
        # containing the team
        self.assertEqual(self.db.get("Barca"), self.team)
        self.assertRaises(ValueError, self.db.get, "Real")
    def test_add_game(self):
        g = Game(self.team, Team("Barcelona"), date(2020, 5, 5), self.field)
        g_l = [g]
        self.team.add_games(g_l)
        self.assertRaises(TypeError, self.team.add_games, g)
        self.assertIn(g, self.team.upcoming_games)
        self.assertIn(g, self.team.upcoming_games)
        self.team.remove_upcoming_game(g)
        self.assertNotIn(g, self.team.upcoming_games)

        self.team.add_game(g)
        self.assertEqual(1, len(self.team.upcoming_games))
        self.assertTrue(self.team.collision_game_check(g))
        self.assertRaises(ValueError, self.team.add_game, g)
        self.assertIn(g, self.team.upcoming_games)
Пример #10
0
class TestGame(TestCase):

    home_team = Team("Barcelona")
    away_team = Team("Real Madrid")
    d = datetime(2020, 5, 5)
    field = "Camp Nou"
    game = Game(home_team, away_team, d, field)

    """ Testing the set main referee method """

    def test_set_main_referee(self):

        referee = Referee(RefereeQualificationEnum.MAIN, 'Dor123', '12345678', 'Dor', datetime(1990, 8, 8), '1.1.1.1', '')
        self.assertRaises(TypeError, self.game.main_referee, main_referee=self.home_team)
        self.game.main_referee = referee
        self.assertEqual(referee, self.game._Game__main_referee)

    """ Testing the set match time method """

    def test_set_match_time(self):

        self.assertRaises(TypeError, self.game.match_time, match_time=[])
        self.assertEqual(datetime(2020, 5, 5), self.game._Game__match_time)

    """ Testing the set field method """

    def test_set_field(self):

        self.assertRaises(TypeError, self.game.field, match_time=0)
        self.assertEqual(self.field, self.game._Game__field)

    """ Testing the set team method """

    def test_set_team(self):

        self.assertRaises(TypeError, self.game.home_team, match_time=0)
        self.assertIsInstance(self.game._Game__home_team, Team)
        self.assertEqual(self.game._Game__home_team, self.home_team)
        self.assertRaises(TypeError, self.game.away_team, match_time=0)
        self.assertIsInstance(self.game._Game__away_team, Team)
        self.assertEqual(self.game._Game__away_team, self.away_team)

    """ Testing the add referee and remove referee methods """

    def test_add_remove_referee(self):

        m_r = Referee(RefereeQualificationEnum.MAIN, 'Dor123', '12345678', 'Dor', datetime(1990, 8, 8), '1.1.1.1', '')
        r = Referee(RefereeQualificationEnum.REGULAR, 'Dor12', '12345678', 'Dor', datetime(1990, 8, 8), '1.1.1.1', '')

        self.game.main_referee = m_r

        self.game.add_referee(r)
        self.assertIn(r, self.game._Game__referees)

        self.game.remove_referee(r)
        self.assertNotIn(r, self.game._Game__referees)

    """ Testing the add event and remove event methods """

    def test_add_remove_event(self):

        r = Referee(RefereeQualificationEnum.MAIN, 'Dor123', '12345678', 'Dor', datetime(1990, 8, 8), '1.1.1.1', '')
        self.game.add_referee(r)
        game_event = GameEvent(self.game, r, "type", "des", datetime(2020, 5, 5), 89)
        g = Game(self.home_team, self.away_team, self.d, self.field)
        g.main_referee = Referee(RefereeQualificationEnum.MAIN, 'Dor12', '12345678', 'Dor', datetime(1990, 8, 8),
                                 '1.1.1.1', '')
        not_game_event = GameEvent(g, g.main_referee,
                                   EventTypeEnum.GOAL, "des", datetime(2020, 5, 5), 89)

        self.assertRaises(ValueError, self.game.add_event, event=not_game_event)
        self.assertNotIn(not_game_event, self.game._Game__events)

        self.assertIn(game_event, self.game._Game__events)
        self.assertRaises(ValueError, self.game.add_event, event=game_event)

        self.game.remove_event(r)
        self.assertNotIn(r, self.game._Game__events)
        self.game.remove_event(game_event)
        self.assertNotIn(game_event, self.game._Game__events)

    """ Testing the team goals methods """

    def test_team_goal(self):

        self.assertEqual(self.game._Game__home_score, 0)
        self.assertEqual(self.game._Game__away_score, 0)
        self.game.home_team_goal()
        self.game.home_team_goal()
        self.game.away_team_goal()
        self.assertEqual(self.game._Game__home_score, 2)
        self.assertEqual(self.game._Game__away_score, 1)

    """ Testing all the class getters """

    def test_getters(self):

        self.assertEqual(self.game.home_team, self.home_team)
        self.assertEqual(self.game.away_team, self.away_team)
        self.assertEqual(self.game.field, self.field)
        self.assertEqual(self.game.match_time, self.d)
        main_ref = self.game.main_referee
        refs = self.game.referees
        self.assertEqual(main_ref, self.game._Game__main_referee)
        self.assertEqual(refs, self.game._Game__referees)
        self.assertEqual(self.game.score['home'], self.game._Game__home_score)
        self.assertEqual(self.game.score['away'], self.game._Game__away_score)
Пример #11
0
class TestFan(TestCase):

    home_team = Team("Barcelona")
    away_team = Team("Real Madrid")
    d = date.datetime(2020, 5, 5)
    field = "Camp Nou"
    game = Game(home_team, away_team, d, field)

    page = PersonalPage("Messi")

    recommend_me = RecommendationSystem()

    def setUp(self):
        user_name = 'default'
        password = '******'
        name = 'default'
        birth_date = date.datetime(2000, 1, 1)
        user_id = 111
        self.fan = Fan(user_name, password, name, birth_date, user_id)

    def tearDown(self):
        pass

    """ Testing the follow personal page method """

    def test_follow_page(self):
        self.fan.follow_page(self.page)
        self.assertRaises(ValueError, self.fan.follow_page, self.page)
        self.assertIn(self.page, self.fan._Fan__followed_pages)

    """ Testing the unfollow personal page method """

    def test_unfollow_page(self):
        self.assertRaises(ValueError, self.fan.unfollow_page, self.page)
        self.fan.follow_page(self.page)
        self.assertIn(self.page, self.fan._Fan__followed_pages)
        self.fan.unfollow_page(self.page)
        self.assertNotIn(self.page, self.fan._Fan__followed_pages)

    """ Testing the follow game method """

    def test_follow_game(self):
        self.fan.follow_game(self.game)
        self.assertRaises(ValueError, self.fan.follow_game, self.game)
        self.assertIn(self.game, self.fan._Fan__followed_games)

    """ Testing the unfollow game method """

    def test_unfollow_game(self):
        self.assertRaises(ValueError, self.fan.unfollow_game, self.game)
        self.fan.follow_game(self.game)
        self.assertIn(self.game, self.fan._Fan__followed_games)
        self.fan.unfollow_game(self.game)
        self.assertNotIn(self.game, self.fan._Fan__followed_games)

    """ Testing for set recommendation system method"""

    def test_set_recommendation_system(self):
        self.fan.set_recommendation_system(self.recommend_me)
        self.assertIs(self.recommend_me, self.fan._Fan__recommendation_system)

    def test_complain(self):
        pass
Пример #12
0
 def setUp(self):
     self.team = Team("Real Madrid")
     self.field = "Camp Nou"
Пример #13
0
class TestTeam(TestCase):
    team = Team("Real Madrid")
    field = "Camp Nou"

    def setUp(self):
        self.team = Team("Real Madrid")
        self.field = "Camp Nou"

    """ Testing the arguments of init"""

    def test_init(self):
        self.assertRaises(TypeError, Team, 4)

    """ Testing the add league method """

    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])

    """ Testing the game over method """

    def test_game_over(self):
        g = Game(self.team, Team("Barcelona"), date(2020, 7, 7), self.field)
        g_error = Game(self.team, Team("RealMadrid"), date(2020, 7, 7),
                       self.field)
        self.team.add_game(g)
        self.team.game_over(g)
        self.assertIn(g, self.team.past_games)
        self.assertNotIn(g, self.team.upcoming_games)
        self.assertRaises(ValueError, self.team.game_over, g_error)

    """ Testing methods:
        1. add_game
        2. add_games
        3. collision_game_check 
        4. remove_upcoming_game """

    def test_add_game(self):
        g = Game(self.team, Team("Barcelona"), date(2020, 5, 5), self.field)
        g_l = [g]
        self.team.add_games(g_l)
        self.assertRaises(TypeError, self.team.add_games, g)
        self.assertIn(g, self.team.upcoming_games)
        self.assertIn(g, self.team.upcoming_games)
        self.team.remove_upcoming_game(g)
        self.assertNotIn(g, self.team.upcoming_games)

        self.team.add_game(g)
        self.assertEqual(1, len(self.team.upcoming_games))
        self.assertTrue(self.team.collision_game_check(g))
        self.assertRaises(ValueError, self.team.add_game, g)
        self.assertIn(g, self.team.upcoming_games)

    """ Testing methods:
        1. add_team_member 
        2. remove_team_member 
        3. add_team_members 
        4. remove_team_members """

    def test_team_members_management(self):

        u1 = TeamUser('user_nam3',
                      'password',
                      'NameC',
                      date(1993, 1, 12),
                      "0.0.0.3",
                      3,
                      team=None,
                      role=Player())
        u2 = TeamUser('user_nam4',
                      'password',
                      'NameD',
                      date(1993, 1, 12),
                      "0.0.0.4",
                      3,
                      team=None,
                      role=Player())
        u_l = [u1, u2]

        self.team.add_team_member(u1)
        self.assertRaises(ValueError,
                          self.team.add_team_member,
                          team_member=u1)
        self.assertEqual(u1.team, self.team)
        self.assertIn(u1, self.team.team_members)

        self.team.remove_team_member(u1)
        self.assertNotIn(u1, self.team.team_members)

        self.assertRaises(TypeError,
                          self.team.add_team_members,
                          team_member=u1)
        self.team.add_team_members(u_l)
        self.assertIn(u1, self.team.team_members)
        self.assertIn(u2, self.team.team_members)

        self.assertRaises(TypeError,
                          self.team.remove_team_members,
                          team_members=0)
        self.team.remove_team_members(u_l)
        self.assertNotIn(u1, self.team.team_members)
        self.assertNotIn(u2, self.team.team_members)

    """ Testing methods:
        1. close_team
        2. open_team """

    def test_open_close(self):
        self.team.close_team()
        self.assertFalse(self.team.is_open)

        self.team.open_team()
        self.assertTrue(self.team.is_open)