Updated PyTests
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
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
This commit is contained in:
1 parent
4f5d071eeb
commit
b7da527e95
2 files changed
+22
-27
No files matched your search
@@ -5,7 +5,6 @@ import pytest
|
|||||||
from app.core.auth import get_admin_user, get_optional_user
|
from app.core.auth import get_admin_user, get_optional_user
|
||||||
from app.database import Base, get_db
|
from app.database import Base, get_db
|
||||||
|
|
||||||
# Import your app and models
|
|
||||||
from app.main import app
|
from app.main import app
|
||||||
from app import models
|
from app import models
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
@@ -15,8 +14,6 @@ from sqlalchemy.orm import Session, sessionmaker
|
|||||||
from sqlalchemy.pool import StaticPool
|
from sqlalchemy.pool import StaticPool
|
||||||
|
|
||||||
# --- DATABASE SETUP ---
|
# --- DATABASE SETUP ---
|
||||||
# Use in-memory SQLite.
|
|
||||||
# StaticPool is CRITICAL for in-memory SQLite with async tests to share connection.
|
|
||||||
SQLALCHEMY_DATABASE_URL = "sqlite:///"
|
SQLALCHEMY_DATABASE_URL = "sqlite:///"
|
||||||
engine = create_engine(
|
engine = create_engine(
|
||||||
SQLALCHEMY_DATABASE_URL,
|
SQLALCHEMY_DATABASE_URL,
|
||||||
@@ -61,14 +58,11 @@ async def client(db: Session) -> AsyncGenerator[AsyncClient, None]:
|
|||||||
finally:
|
finally:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Strict Auth: Always requires a token (simulated by header presence)
|
|
||||||
def override_get_admin_user(request: Request):
|
def override_get_admin_user(request: Request):
|
||||||
if "Authorization" not in request.headers:
|
if "Authorization" not in request.headers:
|
||||||
# Let FastAPI raise the 401 naturally if header is missing
|
|
||||||
raise pytest.skip("Auth header missing in strict auth test")
|
raise pytest.skip("Auth header missing in strict auth test")
|
||||||
return "test_admin"
|
return "test_admin"
|
||||||
|
|
||||||
# Optional Auth: Returns Admin IF header exists, else None
|
|
||||||
def override_get_optional_user(request: Request):
|
def override_get_optional_user(request: Request):
|
||||||
if "Authorization" in request.headers:
|
if "Authorization" in request.headers:
|
||||||
return "test_admin"
|
return "test_admin"
|
||||||
@@ -86,9 +80,6 @@ async def client(db: Session) -> AsyncGenerator[AsyncClient, None]:
|
|||||||
app.dependency_overrides.clear()
|
app.dependency_overrides.clear()
|
||||||
|
|
||||||
|
|
||||||
# --- HELPER FIXTURES ---
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def auth_headers(client):
|
def auth_headers(client):
|
||||||
return {"Authorization": "Bearer test_token"}
|
return {"Authorization": "Bearer test_token"}
|
||||||
@@ -102,13 +93,18 @@ async def valid_tournament_payload(db):
|
|||||||
db.add_all([c1, c2])
|
db.add_all([c1, c2])
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# 2. Return payload with IDs
|
# 2. Return payload with the NEW object format for teams!
|
||||||
return {
|
return {
|
||||||
"name": "Test Tournament",
|
"name": "Test Tournament",
|
||||||
"code": "1234",
|
"code": "1234",
|
||||||
"type": "Double",
|
"type": "Double",
|
||||||
"timestamp": "2026-05-24T11:00:00",
|
"timestamp": "2026-05-24T11:00:00",
|
||||||
"duration": 15,
|
"duration": 15,
|
||||||
"teams": ["Team A", "Team B", "Team C", "Team D"],
|
"teams": [
|
||||||
|
{"id": "temp-1", "name": "Team A", "dropped_out": False},
|
||||||
|
{"id": "temp-2", "name": "Team B", "dropped_out": False},
|
||||||
|
{"id": "temp-3", "name": "Team C", "dropped_out": False},
|
||||||
|
{"id": "temp-4", "name": "Team D", "dropped_out": False},
|
||||||
|
],
|
||||||
"courts": [c1.id, c2.id],
|
"courts": [c1.id, c2.id],
|
||||||
}
|
}
|
||||||
@@ -24,12 +24,14 @@ async def test_manage_teams(
|
|||||||
# 2. Verify Bracket Regenerated
|
# 2. Verify Bracket Regenerated
|
||||||
detail_res = await client.get(f"/tournaments/{t_id}")
|
detail_res = await client.get(f"/tournaments/{t_id}")
|
||||||
matches = detail_res.json()["matches"]
|
matches = detail_res.json()["matches"]
|
||||||
|
|
||||||
# With 5 teams, bracket size increases
|
|
||||||
assert len(matches) > 3
|
assert len(matches) > 3
|
||||||
|
|
||||||
# 3. Bulk Update
|
# 3. Bulk Update - FIX: Send the new object format!
|
||||||
new_team_list = ["Team X", "Team Y"]
|
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(
|
patch_res = await client.patch(
|
||||||
f"/tournaments/{t_id}/teams", json=new_team_list, headers=auth_headers
|
f"/tournaments/{t_id}/teams", json=new_team_list, headers=auth_headers
|
||||||
)
|
)
|
||||||
@@ -37,21 +39,18 @@ async def test_manage_teams(
|
|||||||
|
|
||||||
updated_detail = await client.get(f"/tournaments/{t_id}")
|
updated_detail = await client.get(f"/tournaments/{t_id}")
|
||||||
final_matches = updated_detail.json()["matches"]
|
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
|
assert len(final_matches) >= 1
|
||||||
|
|
||||||
# Verify the teams are actually in the first match
|
# Verify the teams are actually in the first match
|
||||||
first_match = final_matches[0]
|
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 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 first_match["p2_team_id"] is not None
|
||||||
|
assert isinstance(first_match["p2_team_id"], int)
|
||||||
p1_name = first_match["p1_team_id"]
|
|
||||||
p2_name = first_match["p2_team_id"]
|
|
||||||
|
|
||||||
assert 6 == p1_name
|
|
||||||
assert 7 == p2_name
|
|
||||||
|
|
||||||
|
|
||||||
async def test_manage_courts(
|
async def test_manage_courts(
|
||||||
@@ -76,7 +75,7 @@ async def test_manage_courts(
|
|||||||
|
|
||||||
# CREATE: Change this from a tournament-specific route to the global one
|
# CREATE: Change this from a tournament-specific route to the global one
|
||||||
create_res = await client.post(
|
create_res = await client.post(
|
||||||
"/courts", json={"name": "New Court"}, headers=auth_headers # GLOBAL ROUTE
|
"/courts", json={"name": "New Court"}, headers=auth_headers
|
||||||
)
|
)
|
||||||
assert create_res.status_code == 200
|
assert create_res.status_code == 200
|
||||||
assert create_res.json()["name"] == "New Court"
|
assert create_res.json()["name"] == "New Court"
|
||||||
Reference in new issue
Block a user