Better bracket logic

This commit is contained in:
2026-02-14 01:04:54 +01:00 Verified
parent 87d3ea5ef0
commit 7b878b3abe
32 changed files with 1326 additions and 1348 deletions
+28 -10
View File
@@ -20,14 +20,13 @@ async def test_manage_teams(
f"/tournaments/{t_id}/teams", json=new_team, headers=auth_headers
)
assert post_res.status_code == 200
assert post_res.json()["name"] == "Team E"
# 2. Verify Bracket Regenerated (Call new endpoint)
bracket_res = await client.get(f"/tournaments/{t_id}/bracket")
nodes = bracket_res.json()
# 2. Verify Bracket Regenerated
detail_res = await client.get(f"/tournaments/{t_id}")
matches = detail_res.json()["matches"]
# With 5 teams -> size 8 bracket
assert len(nodes) > 4
# With 5 teams, bracket size increases
assert len(matches) > 3
# 3. Bulk Update
new_team_list = ["Team X", "Team Y"]
@@ -35,8 +34,27 @@ async def test_manage_teams(
f"/tournaments/{t_id}/teams", json=new_team_list, headers=auth_headers
)
assert patch_res.status_code == 200
data = patch_res.json()
assert len(data) == 2
updated_detail = await client.get(f"/tournaments/{t_id}")
final_matches = updated_detail.json()["matches"]
# Fix: For Double Elim with 2 teams, we might get 2 matches (WB Final + Grand Final).
# Just ensure we have at least 1 match.
assert len(final_matches) >= 1
# Verify the teams are actually in the first match
first_match = next(
m
for m in final_matches
if m["name"] == "Winners Final"
or m["name"] == "Grand Final"
or m["name"].startswith("WB")
)
p1_name = first_match["p1_team"]["name"] if first_match["p1_team"] else None
p2_name = first_match["p2_team"]["name"] if first_match["p2_team"] else None
assert "Team X" in [p1_name, p2_name]
assert "Team Y" in [p1_name, p2_name]
async def test_manage_courts(
@@ -48,8 +66,8 @@ async def test_manage_courts(
t_id = res.json()["id"]
# Get initial courts
courts_res = await client.get(f"/tournaments/{t_id}/courts")
initial_courts = courts_res.json()
courts_res = await client.get(f"/tournaments/{t_id}")
initial_courts = courts_res.json()["courts"]
assert len(initial_courts) == 2
# Delete