Beispiel #1
0
 def setUp(self):
     self.logPoint()
     self.team = Team()
     self.forward = PlayerForward(47, "Sven", "Baertschi", 180.34, 190, 47, "Oct 5, 1992", "2011", "LW", "L", 8, 5, 40)
     self.goalie = PlayerGoalie(1, "Roberto", "Luongo", 190.5, 215, 1, "Apr 4, 1979", 1997, 788, 83, 705, 30, 12, 13)
     self.undefined_value = None
     self.empty_value = ""
Beispiel #2
0
    def _read_player_from_file(self):
        """ Private method to load the JSON player records from the file at _filepath into the list of players """

        with open(self._filepath) as player_file:
            data = player_file.read()

            if (data== None) or (data == ""):
                return

            players_obj = json.loads(data)

            for key, value in players_obj.items():
                if key.lower() == "forward":
                    for i in value:
                        player = PlayerForward(i['fname'], i['lname'], i['height'], i['weight'], i['jersey_num'], i['date_birth'],
                                               i['year_joined'], i['zone'], i['shooting_hand'], i['goals'], i['assists'], i['total_shots'], i['player_type'])
                        player.set_id(i['id'])
                        self._team_players.append(player)
                elif key.lower() == "goalie":
                    for i in value:
                        player = PlayerGoalie(i['fname'], i['lname'], i['height'], i['weight'], i['jersey_num'], i['date_birth'], i['year_joined'],
                                              i['shots_against'], i['goals_against'], i['goals_saved'], i['games_played'], i['games_won'], i['games_lost'], i['player_type'])
                        player.set_id(i['id'])
                        self._team_players.append(player)
                else:
                    continue

        return
def update_player(player_id):
    """ Updates player's attributes """
    content = request.json

    try:
        player_type = content["player_type"].lower()

        if player_type == PLAYER_TYPE_FORWARD:
            player = PlayerForward(content["fname"], content["lname"], content["height"], content["weight"], content["jersey_num"], content["date_birth"], content["year_joined"], content["zone"], content["shooting_hand"], content["goals"], content["assists"], content["total_shots"], content["player_type"])
            player.set_id(player_id)
            team.update(player)
            response = app.response_class(
                status=200
            )
        elif player_type == PLAYER_TYPE_GOALIE:
            player = PlayerGoalie(content["fname"], content["lname"], content["height"], content["weight"], content["jersey_num"], content["date_birth"], content["year_joined"], content["shots_against"], content["goals_against"], content["goals_saved"], content["games_played"], content["games_won"], content["games_lost"], content["player_type"])
            player.set_id(player_id)
            team.update(player)
            response = app.response_class(
                status=200
            )
        else:
            raise Exception

    except ValueError as e:
        response = app.response_class(
            status=404,
            response=str(e)
        )

    return response
 def setUp(self):
     self.logPoint()
     self.test_player_forward = PlayerForward("Sven", "Baertschi", 180.34,
                                              190, 47, "Oct 5, 1992",
                                              "2011", "LW", "L", 8, 5, 40,
                                              "Forward")
     self.none_value = None
     self.empty_value = ""
Beispiel #5
0
    def test_update(self):
        """ 070A: Valid Update """

        self.logPoint()

        self.team.add(self.forward)
        self.team.add(self.goalie)

        new_forward = PlayerForward(47, "Yann", "Sauve", 190.5, 207.24, 47, "Feb 18, 1990", "2008", "RW", "L", 12, 8, 43)

        self.team.update(new_forward)

        self.assertEqual(self.team.get_player(47).get_full_name(), "Yann Sauve")
Beispiel #6
0
    def setUp(self):
        """ Creates test fixture """
        self.logPoint()

        json.load = MagicMock(return_value=TestTeam.TEST_PLAYERS)
        self.team = Team("testplayers.json")

        self.forward = PlayerForward("Sven", "Baertschi", 180.34, 190, 47,
                                     "Oct 5, 1992", "2011", "LW", "L", 8, 5,
                                     40, "forward")
        self.forward_id = id(self.forward)
        (self.forward).set_id(self.forward_id)

        self.goalie = PlayerGoalie("Roberto", "Luongo", 190.5, 215, 1,
                                   "Apr 4, 1979", 1997, 788, 83, 705, 30, 12,
                                   13, "goalie")
        self.goalie_id = id(self.goalie)
        (self.goalie).set_id(self.goalie_id)

        self.undefined_value = None
        self.empty_value = ""
def add_player():
    """ Adds a player to the team """
    content = request.json

    try:
        player_type = content["player_type"].lower()

        if player_type == PLAYER_TYPE_FORWARD:
            player = PlayerForward(content["fname"], content["lname"], content["height"], content["weight"], content["jersey_num"], content["date_birth"], content["year_joined"], content["zone"], content["shooting_hand"], content["goals"], content["assists"], content["total_shots"], content["player_type"])

            team.add(player)

            id = str(player.get_id())

            response = app.response_class(
                status=200,
                response=id
            )
        elif player_type == PLAYER_TYPE_GOALIE:
            player = PlayerGoalie(content["fname"], content["lname"], content["height"], content["weight"], content["jersey_num"], content["date_birth"], content["year_joined"], content["shots_against"], content["goals_against"], content["goals_saved"], content["games_played"], content["games_won"], content["games_lost"], content["player_type"])

            team.add(player)

            id = str(player.get_id())

            response = app.response_class(
                status=200,
                response=id
            )
        else:
            raise Exception
    except:
        response = app.response_class(
            response="Player is invalid",
            status=400
        )

    return response
 def setUp(self):
     self.logPoint()
     self.test_player_forward = PlayerForward(47, "Sven", "Baertschi",
                                              180.34, 190, 47,
                                              "Oct 5, 1992", "2011", "LW",
                                              "L", 8, 5, 40)
Beispiel #9
0
from player_forward import PlayerForward
from player_goalie import PlayerGoalie
from team import Team
import json
import os

player1 = PlayerForward("Sven", "Baertschi", 180.34, 190, 47, "Oct 5, 1992",
                        "2011", "LW", "L", 8, 5, 40, "forward")
player2 = PlayerForward("John", "Doe", 123, 23, 3, "Sept 2, 2534", "1234",
                        "WN", "R", 3, 5, 65, "Forward")
player3 = PlayerGoalie("Bob", "Smith", 321, 100, 4, "Jan 1, 1990", "2000", 123,
                       432, 40, 20, 20, 20, "goalie")

team = Team("./players.json")

#team.add(player1)
#team.add(player2)
#team.add(player3)

#player3_id = player3.get_id()

#print(id((team.get_all_players())[0]))
# team.delete(id(player2))

#player_list = team.get_all_players()
#player1 = player_list[0]
#print(player1.to_dict())

#print(json.dumps((team.get_all_players())["2380120105032"], indent=4))

team.add(player1)
Beispiel #10
0
from team import Team
from player_forward import PlayerForward
from player_goalie import PlayerGoalie

team_a = Team()
forward = PlayerForward(47, "Sven", "Baertschi", 180.34, 190, 47,
                        "Oct 5, 1992", "2011", "LW", "L", 8, 5, 40)
goalie = PlayerGoalie(1, "Roberto", "Luongo", 190.5, 215, 1, "Apr 4, 1979",
                      1997, 788, 83, 705, 30, 12, 13)

forward_update = PlayerForward(47, "QUACK", "Baertschi", 180.34, 190, 47,
                               "Oct 5, 1992", "2011", "LW", "L", 8, 5, 40)

team_a.add(forward)
team_a.add(goalie)

team_a.update(forward_update)

list_players = team_a.get_all_players()

player_1 = list_players[0].get_fname()
player_2 = list_players[1].get_fname()

print(player_1)
print(player_2)