feat: show matching season context in player results

This commit is contained in:
bisco
2026-04-07 16:31:00 +02:00
parent b351d31cf5
commit dbf218e2fd
3 changed files with 126 additions and 3 deletions

View File

@ -134,6 +134,37 @@ class ScoutingSearchViewsTests(TestCase):
self.assertContains(response, self.player_pg.full_name)
self.assertNotContains(response, self.player_wing.full_name)
def test_result_row_shows_matching_context_for_filtered_search(self):
response = self.client.get(
reverse("scouting:player_list"),
{
"competition": self.comp_a.id,
"season": self.season_2025.id,
"team": self.team_a.id,
"min_ts_pct": "57",
},
)
player = next(player for player in response.context["players"] if player.id == self.player_pg.id)
self.assertEqual(player.matching_context.id, self.ctx_pg_good.id)
self.assertContains(response, "Match context:")
self.assertContains(response, self.season_2025.name)
self.assertContains(response, "PTS 16.00")
def test_result_row_does_not_show_non_matching_context(self):
response = self.client.get(
reverse("scouting:player_list"),
{
"competition": self.comp_a.id,
"season": self.season_2025.id,
"team": self.team_a.id,
"min_ts_pct": "57",
},
)
player = next(player for player in response.context["players"] if player.id == self.player_pg.id)
self.assertEqual(player.matching_context.id, self.ctx_pg_good.id)
self.assertNotContains(response, "PTS 10.00")
self.assertNotContains(response, "AST 4.00")
def test_no_false_positive_from_different_context_rows(self):
response = self.client.get(
reverse("scouting:player_list"),
@ -157,6 +188,44 @@ class ScoutingSearchViewsTests(TestCase):
self.assertContains(response, self.player_pg.full_name)
self.assertNotContains(response, self.player_wing.full_name)
def test_matching_context_selection_is_deterministic_when_multiple_contexts_match(self):
second_matching_context = PlayerSeason.objects.create(
player=self.player_pg,
season=self.season_2024,
team=self.team_a,
competition=self.comp_a,
)
PlayerSeasonStats.objects.create(
player_season=second_matching_context,
points=Decimal("18.00"),
assists=Decimal("6.20"),
steals=Decimal("1.50"),
turnovers=Decimal("2.00"),
blocks=Decimal("0.20"),
efg_pct=Decimal("52.00"),
ts_pct=Decimal("57.50"),
plus_minus=Decimal("3.50"),
offensive_rating=Decimal("110.00"),
defensive_rating=Decimal("105.00"),
)
response = self.client.get(
reverse("scouting:player_list"),
{
"competition": self.comp_a.id,
"team": self.team_a.id,
},
)
player = next(player for player in response.context["players"] if player.id == self.player_pg.id)
self.assertEqual(player.matching_context.id, self.ctx_pg_good.id)
self.assertContains(response, self.season_2025.name)
self.assertNotContains(response, "PTS 18.00")
def test_player_detail_page_still_loads_after_related_loading_cleanup(self):
response = self.client.get(reverse("scouting:player_detail", args=[self.player_pg.id]))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "PTS 16.00")
def test_combined_team_and_defensive_rating_quality_filter(self):
response = self.client.get(
reverse("scouting:player_list"),