Align balldontlie OpenAPI integration and clarify search metric semantics
This commit is contained in:
@ -128,6 +128,57 @@ def test_players_api_search_consistent_with_ui_filters(client):
|
||||
assert api_response.json()["results"][0]["id"] == matching.id
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_players_api_metric_sort_uses_best_eligible_values(client):
|
||||
nationality = Nationality.objects.create(name="Romania", iso2_code="RO", iso3_code="ROU")
|
||||
competition = Competition.objects.create(
|
||||
name="LNBM",
|
||||
slug="lnbm",
|
||||
competition_type=Competition.CompetitionType.LEAGUE,
|
||||
gender=Competition.Gender.MEN,
|
||||
country=nationality,
|
||||
)
|
||||
season_old = Season.objects.create(label="2022-2023", start_date=date(2022, 9, 1), end_date=date(2023, 6, 30))
|
||||
season_new = Season.objects.create(label="2023-2024", start_date=date(2023, 9, 1), end_date=date(2024, 6, 30))
|
||||
team = Team.objects.create(name="Bucharest", slug="bucharest", country=nationality)
|
||||
|
||||
p1 = Player.objects.create(first_name="Ion", last_name="Low", full_name="Ion Low", nationality=nationality)
|
||||
p1s = PlayerSeason.objects.create(
|
||||
player=p1,
|
||||
season=season_old,
|
||||
team=team,
|
||||
competition=competition,
|
||||
games_played=20,
|
||||
minutes_played=400,
|
||||
)
|
||||
PlayerSeasonStats.objects.create(player_season=p1s, points=13, rebounds=3, assists=2, steals=1, blocks=0.1, turnovers=2)
|
||||
|
||||
p2 = Player.objects.create(first_name="Dan", last_name="High", full_name="Dan High", nationality=nationality)
|
||||
p2s_old = PlayerSeason.objects.create(
|
||||
player=p2,
|
||||
season=season_old,
|
||||
team=team,
|
||||
competition=competition,
|
||||
games_played=20,
|
||||
minutes_played=400,
|
||||
)
|
||||
PlayerSeasonStats.objects.create(player_season=p2s_old, points=9, rebounds=3, assists=2, steals=1, blocks=0.1, turnovers=2)
|
||||
p2s_new = PlayerSeason.objects.create(
|
||||
player=p2,
|
||||
season=season_new,
|
||||
team=team,
|
||||
competition=competition,
|
||||
games_played=20,
|
||||
minutes_played=500,
|
||||
)
|
||||
PlayerSeasonStats.objects.create(player_season=p2s_new, points=22, rebounds=5, assists=4, steals=1.3, blocks=0.2, turnovers=2.3)
|
||||
|
||||
response = client.get(reverse("api:players"), data={"sort": "ppg_desc"})
|
||||
assert response.status_code == 200
|
||||
names = [row["full_name"] for row in response.json()["results"]]
|
||||
assert names.index("Dan High") < names.index("Ion Low")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_player_detail_api_includes_origin_fields(client):
|
||||
nationality = Nationality.objects.create(name="Greece", iso2_code="GR", iso3_code="GRC")
|
||||
|
||||
Reference in New Issue
Block a user