Files
brackets/backend/tests/test_structure.py
T
WilliamSoderberg Verified b7da527e95
Test and Release / test-backend (push) Successful in 6s
Test and Release / test-frontend (push) Successful in 11s
Test and Release / build-docker (backend) (push) Skipped
Test and Release / build-docker (frontend) (push) Skipped
Test and Release / test-backend (release) Successful in 6s
Test and Release / test-frontend (release) Successful in 11s
Test and Release / build-docker (backend) (release) Successful in 27s
Test and Release / build-docker (frontend) (release) Successful in 26s
Updated PyTests
2026-08-29 21:05:58 +02:00

81 lines
2.7 KiB
Python

# backend/tests/test_structure.py
import pytest
from httpx import AsyncClient
pytestmark = pytest.mark.anyio
async def test_manage_teams(
client: AsyncClient, auth_headers, valid_tournament_payload
):
# Setup
res = await client.post(
"/tournaments", json=valid_tournament_payload, headers=auth_headers
)
t_id = res.json()["id"]
# 1. Add a Team
new_team = {"name": "Team E"}
post_res = await client.post(
f"/tournaments/{t_id}/teams", json=new_team, headers=auth_headers
)
assert post_res.status_code == 200
# 2. Verify Bracket Regenerated
detail_res = await client.get(f"/tournaments/{t_id}")
matches = detail_res.json()["matches"]
assert len(matches) > 3
# 3. Bulk Update - FIX: Send the new object format!
new_team_list = [
{"id": "temp-x", "name": "Team X", "dropped_out": False},
{"id": "temp-y", "name": "Team Y", "dropped_out": False},
]
patch_res = await client.patch(
f"/tournaments/{t_id}/teams", json=new_team_list, headers=auth_headers
)
assert patch_res.status_code == 200
updated_detail = await client.get(f"/tournaments/{t_id}")
final_matches = updated_detail.json()["matches"]
assert len(final_matches) >= 1
# Verify the teams are actually in the first match
first_match = final_matches[0]
# FIX: Safely assert they have IDs assigned without hardcoding exact numbers
# (since auto-increment IDs can fluctuate in test environments)
assert first_match["p1_team_id"] is not None
assert isinstance(first_match["p1_team_id"], int)
assert first_match["p2_team_id"] is not None
assert isinstance(first_match["p2_team_id"], int)
async def test_manage_courts(
client: AsyncClient, auth_headers, valid_tournament_payload
):
res = await client.post(
"/tournaments", json=valid_tournament_payload, headers=auth_headers
)
t_id = res.json()["id"]
# 1. Get initial courts from the tournament detail
courts_res = await client.get(f"/tournaments/{t_id}")
initial_courts = courts_res.json()["courts"]
assert len(initial_courts) == 2
# 2. Extract the ID from the list so the variable is defined!
court_to_delete_id = initial_courts[0]["id"]
# 3. Now use that variable in your delete call
del_res = await client.delete(f"/courts/{court_to_delete_id}", headers=auth_headers)
assert del_res.status_code == 200
# CREATE: Change this from a tournament-specific route to the global one
create_res = await client.post(
"/courts", json={"name": "New Court"}, headers=auth_headers
)
assert create_res.status_code == 200
assert create_res.json()["name"] == "New Court"