67 lines
2.1 KiB
Python
67 lines
2.1 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 via POST
|
|
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
|
|
assert post_res.json()["name"] == "Team E"
|
|
|
|
# 2. Verify Bracket Regenerated (Match count should likely change or re-seed)
|
|
matches_res = await client.get(f"/tournaments/{t_id}/matches")
|
|
# With 4 teams -> ~6 matches. With 5 teams -> ~8-10 matches in Double Elim.
|
|
assert len(matches_res.json()) > 0
|
|
|
|
# 3. Bulk Update via PATCH (Replace all teams)
|
|
new_team_list = ["Team X", "Team Y"]
|
|
patch_res = await client.patch(
|
|
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
|
|
assert data[0]["name"] in ["Team X", "Team Y"]
|
|
|
|
|
|
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"]
|
|
|
|
# Get initial courts
|
|
courts_res = await client.get(f"/tournaments/{t_id}/courts")
|
|
initial_courts = courts_res.json()
|
|
assert len(initial_courts) == 2
|
|
|
|
# Delete a court
|
|
court_id = initial_courts[0]["id"]
|
|
del_res = await client.delete(
|
|
f"/tournaments/{t_id}/courts/{court_id}", headers=auth_headers
|
|
)
|
|
assert del_res.status_code == 200
|
|
|
|
# Create a court
|
|
create_res = await client.post(
|
|
f"/tournaments/{t_id}/courts", json={"name": "New Court"}, headers=auth_headers
|
|
)
|
|
assert create_res.status_code == 200
|
|
assert create_res.json()["name"] == "New Court"
|