Skip to content

Commit

Permalink
[70] Contract attribute using wrong source (#71)
Browse files Browse the repository at this point in the history
* fix: player contracts and signed from

* fix: unit tests
  • Loading branch information
felipeall authored Aug 14, 2024
1 parent 3e18650 commit 62cfa0c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
9 changes: 2 additions & 7 deletions app/services/clubs/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __parse_club_players(self) -> list[dict]:
Clubs.Players.Past.PAGE_SIGNED_FROM if self.past else Clubs.Players.Present.PAGE_SIGNED_FROM,
)
page_players_joined_on = self.page.xpath(
Clubs.Players.Past.PAGE_SIGNED_FROM if self.past else Clubs.Players.Present.PAGE_SIGNED_FROM,
Clubs.Players.Past.PAGE_JOINED_ON if self.past else Clubs.Players.Present.PAGE_JOINED_ON,
)
players_ids = [extract_from_url(url) for url in self.get_list_by_xpath(Clubs.Players.URLS)]
players_names = self.get_list_by_xpath(Clubs.Players.NAMES)
Expand All @@ -77,9 +77,6 @@ def __parse_club_players(self) -> list[dict]:
players_joined_on = ["; ".join(e.xpath(Clubs.Players.JOINED_ON)) for e in page_players_joined_on]
players_joined = ["; ".join(e.xpath(Clubs.Players.JOINED)) for e in page_players_infos]
players_signed_from = ["; ".join(e.xpath(Clubs.Players.SIGNED_FROM)) for e in page_players_signed_from]
players_contracts = (
[None] * len(players_ids) if self.past else self.get_list_by_xpath(Clubs.Players.Past.CONTRACTS)
)
players_marketvalues = self.get_list_by_xpath(Clubs.Players.MARKET_VALUES)
players_statuses = ["; ".join(e.xpath(Clubs.Players.STATUSES)) for e in page_players_infos]

Expand All @@ -97,11 +94,10 @@ def __parse_club_players(self) -> list[dict]:
"joinedOn": joined_on,
"joined": joined,
"signedFrom": signed_from,
"contract": contract,
"marketValue": market_value,
"status": status,
}
for idx, name, position, dob, age, nationality, current_club, height, foot, joined_on, joined, signed_from, contract, market_value, status, in zip( # noqa: E501
for idx, name, position, dob, age, nationality, current_club, height, foot, joined_on, joined, signed_from, market_value, status, in zip( # noqa: E501
players_ids,
players_names,
players_positions,
Expand All @@ -114,7 +110,6 @@ def __parse_club_players(self) -> list[dict]:
players_joined_on,
players_joined,
players_signed_from,
players_contracts,
players_marketvalues,
players_statuses,
)
Expand Down
2 changes: 0 additions & 2 deletions app/utils/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,13 @@ class Present:
PAGE_JOINED_ON = "//div[@id='yw1']//td[7]"
HEIGHTS = "//div[@id='yw1']//td[5]//text()"
FOOTS = "//div[@id='yw1']//td[6]//text()"
CONTRACTS = "//div[@id='yw1']//td[9]//text()"

class Past:
PAGE_SIGNED_FROM = "//div[@id='yw1']//td[9]"
PAGE_JOINED_ON = "//div[@id='yw1']//td[8]"
CURRENT_CLUB = "//div[@id='yw1']//td[5]//img//@title"
HEIGHTS = "//div[@id='yw1']//td[6]/text()"
FOOTS = "//div[@id='yw1']//td[7]//text()"
CONTRACTS = "//div[@id='yw1']//td[10]//text()"


class Competitions:
Expand Down
3 changes: 1 addition & 2 deletions tests/clubs/test_clubs_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ def test_get_club_players(
"currentClub": Or(None, And(str, len_greater_than_0)),
"height": And(str, len_greater_than_0, regex_height),
"foot": And(str, len_greater_than_0),
"joinedOn": And(str, len_greater_than_0, regex_date_mmm_dd_yyyy),
"joinedOn": Or("", And(str, len_greater_than_0, regex_date_mmm_dd_yyyy)),
"joined": Or("", And(str, len_greater_than_0)),
"signedFrom": Or("", And(str, len_greater_than_0)),
"contract": Or(None, And(str, len_greater_than_0, regex_market_value)),
"marketValue": And(str, len_greater_than_0, regex_market_value),
"status": Or("", And(str, len_greater_than_0)),
},
Expand Down
2 changes: 1 addition & 1 deletion tests/players/test_players_injuries.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_get_player_injuries(player_id, page_number, len_greater_than_0, regex_i
"season": And(str, len_greater_than_0),
"injury": And(str, len_greater_than_0),
"from": And(str, len_greater_than_0, regex_date_mmm_dd_yyyy),
"until": And(str, len_greater_than_0, regex_date_mmm_dd_yyyy),
Optional("until"): And(str, len_greater_than_0, regex_date_mmm_dd_yyyy),
"days": And(str, len_greater_than_0),
Optional("gamesMissed"): And(str, len_greater_than_0, regex_integer),
Optional("gamesMissedClubs"): list[str],
Expand Down
2 changes: 1 addition & 1 deletion tests/players/test_players_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_get_player_profile_8198(len_greater_than_0):
"url": And(str, len_greater_than_0),
"name": And(str, len_greater_than_0),
"description": And(str, len_greater_than_0),
"fullName": And(str, len_greater_than_0),
"nameInHomeCountry": And(str, len_greater_than_0),
"imageURL": And(str, len_greater_than_0),
"dateOfBirth": And(str, len_greater_than_0),
"placeOfBirth": {
Expand Down

0 comments on commit 62cfa0c

Please sign in to comment.