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)
예제 #2
0
 def test_ship_can_shoot_only_once_during_reload_time(self):
     map_ = get_map(ship_location=Vector(40, 100))
     game = Game(1, 1)
     game.Map = map_
     game.ship.shooting = True
     for i in range(game.ship.current_bullet_type.RELOAD_TIME + 1):
         game.shoot()
         game.ship.reload_bullet()
     self.assertEqual(1, len(map_.bullets))
 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 test_col(self):
     w, h = 80, 200
     map_ = Map(w, h)
     map_.ship = Ship(Vector(40, 101), [0, 0, 0])
     map_.asteroids = [AsteroidMediumStrong(Vector(40, 40), radius=40)]
     game = Game(w, h)
     game.Map = map_  # ship делает шаг длины 2
     game.handle_collisions()
     map_.ship.update_ship_location()
     self.assertEqual(103, map_.ship.location.y)
예제 #7
0
def get_map(ship_location):
    w, h = 80, 200
    map_ = Map(w, h)
    map_.ship = Ship(ship_location, {
        BulletFast: 50,
        BulletMedium: 50,
        BulletSlow: 50
    })
    game = Game(w, h)
    game.Map = map_  # ship делает шаг длины 2
    return map_
 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)
예제 #9
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
예제 #10
0
    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)
예제 #11
0
    def game_dict_to_object(self, game_dict):

        match_time_str = game_dict['_Game__match_time']
        date_split = match_time_str.split('.')
        match_time_object = datetime(int(date_split[2]), int(date_split[1]),
                                     int(date_split[0]))

        game_object = Game(game_dict['_Game__game_id'],
                           game_dict['_Game__home_team'],
                           game_dict['_Game__away_team'], match_time_object,
                           game_dict['_Game__field'])

        game_object.home_score = game_dict['_Game__home_score']
        game_object.away_score = game_dict['_Game__away_score']
        game_object.main_referee = game_dict['_Game__main_referee']
        game_object.referees = game_dict['_Game__referees']
        game_object.events = game_dict['_Game__events']
        game_object.is_game_on = game_dict['_Game__is_game_on']
        game_object.is_game_finished = game_dict['_Game__is_game_finished']
        game_object.fan_following = game_dict['fan_following']

        return game_object
예제 #12
0
    def run_game(self):
        game = Game(self.win_params.width, self.win_params.height, self.shop)
        game.shop.reset_if_arsenal_is_empty()
        self.all_sprites = pygame.sprite.Group()
        self.add_starting_sprites(game.Map.map_objects)
        while game.running:
            game.Map.removing_objects.clear()
            game.Map.new_objects.clear()

            self.clock.tick(FPS)
            self.handle_keys_events(game)
            game.finish_if_required()
            game.handle_collisions()
            game.update()

            self.update_sprites_list(game.Map)
            self.draw(game)

        return game.get_results()
예제 #13
0
    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)
예제 #14
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)
예제 #15
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