Updated backend tests with new courts

This commit is contained in:
2026-05-24 16:16:12 +02:00 Verified
parent 33e623b337
commit 4cfdbad442
2 changed files with 31 additions and 12 deletions
+20 -3
View File
@@ -7,6 +7,7 @@ from app.database import Base, get_db
# Import your app and models
from app.main import app
from app import models
from fastapi import Request
from httpx import ASGITransport, AsyncClient
from sqlalchemy import create_engine
@@ -43,6 +44,15 @@ def db(prepare_db) -> Generator[Session, None, None]:
connection.close()
@pytest.fixture(autouse=True)
def clean_db(db):
db.query(models.Match).delete()
db.query(models.Team).delete()
db.query(models.Court).delete()
db.commit()
yield
@pytest.fixture(scope="function")
async def client(db: Session) -> AsyncGenerator[AsyncClient, None]:
def override_get_db():
@@ -85,13 +95,20 @@ def auth_headers(client):
@pytest.fixture
def valid_tournament_payload():
async def valid_tournament_payload(db):
# 1. Create global courts first
c1 = models.Court(name="Plan 1")
c2 = models.Court(name="Plan 2")
db.add_all([c1, c2])
db.commit()
# 2. Return payload with IDs
return {
"name": "Test Tournament",
"code": "1234",
"type": "Double",
"timestamp": "2024-01-01T10:00:00",
"timestamp": "2026-05-24T11:00:00",
"duration": 15,
"teams": ["Team A", "Team B", "Team C", "Team D"],
"courts": ["Court 1", "Court 2"],
"courts": [c1.id, c2.id],
}