Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mypy = "1.14.1"
pluggy = "1.5.0"
pylint = "3.3.1"
pytest = "8.3.4"
pytest-asyncio = "0.21.2"
pytest-asyncio = "0.25.3"
pytest-cov = "6.0.0"
pytest-xdist = "3.6.1"
ruff = "0.9.1"
Expand Down
9 changes: 7 additions & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ filterwarnings = [
'ignore:.*The event_loop fixture provided by pytest-asyncio has been redefined.*:DeprecationWarning',
'ignore:.*Please use `import python_multipart` instead.*:PendingDeprecationWarning',
]
# Enable these once `asyncio_default_test_loop_scope` has been released
# Then remove the `@pytest.mark.asyncio(loop_scope="session")` calls.
#asyncio_default_fixture_loop_scope = "session"
#asyncio_default_test_loop_scope = "session"

[tool.mypy]
junit_xml = '.junit_report.xml'
Expand Down Expand Up @@ -119,10 +123,11 @@ min_confidence = 0
paths = ["."]
ignore_decorators = ["@pytest.*", "@*router*", "@app.*", "@*validator*"]
ignore_names = [
"todo*",
"RestartableUvicornWorker",
"_generate_next_value_",
"downgrade",
"upgrade"
"startup_and_shutdown_uvicorn_server",
"todo*",
"upgrade",
]
sort_by_size = true
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from bracket.logic.scheduling.builder import build_matches_for_stage_item
from bracket.models.db.match import MatchBody, MatchWithDetailsDefinitive
from bracket.models.db.stage_item import StageItemWithInputsCreate
Expand Down Expand Up @@ -28,6 +30,7 @@
)


@pytest.mark.asyncio(loop_scope="session")
async def test_activate_next_stage(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
6 changes: 6 additions & 0 deletions backend/tests/integration_tests/api/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import Mock, patch

import jwt
import pytest

from bracket.config import config
from bracket.models.db.account import UserAccountType
Expand All @@ -21,6 +22,7 @@ def mock_auth_time() -> Generator[None, None, None]:
yield


@pytest.mark.asyncio(loop_scope="session")
async def test_get_token_success(startup_and_shutdown_uvicorn_server: None) -> None:
mock_user = get_mock_user()
body = {
Expand All @@ -38,6 +40,7 @@ async def test_get_token_success(startup_and_shutdown_uvicorn_server: None) -> N
assert decoded == {"user": mock_user.email, "exp": 7258723200}


@pytest.mark.asyncio(loop_scope="session")
async def test_get_token_invalid_credentials(startup_and_shutdown_uvicorn_server: None) -> None:
mock_user = get_mock_user()
body = {
Expand All @@ -51,6 +54,7 @@ async def test_get_token_invalid_credentials(startup_and_shutdown_uvicorn_server
assert response == {"detail": "Incorrect email or password"}


@pytest.mark.asyncio(loop_scope="session")
async def test_auth_on_protected_endpoint(startup_and_shutdown_uvicorn_server: None) -> None:
mock_user = get_mock_user()
headers = {"Authorization": f"Bearer {get_mock_token(mock_user)}"}
Expand All @@ -71,13 +75,15 @@ async def test_auth_on_protected_endpoint(startup_and_shutdown_uvicorn_server: N
}


@pytest.mark.asyncio(loop_scope="session")
async def test_invalid_token(startup_and_shutdown_uvicorn_server: None) -> None:
headers = {"Authorization": "Bearer some.invalid.token"}

response = JsonDict(await send_request(HTTPMethod.GET, "users/me", {}, None, headers))
assert response == {"detail": "Could not validate credentials"}


@pytest.mark.asyncio(loop_scope="session")
async def test_not_authenticated_for_tournament(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from heliclockter import datetime_utc

from bracket.models.db.round import RoundInsertable
Expand Down Expand Up @@ -28,6 +29,7 @@
)


@pytest.mark.asyncio(loop_scope="session")
async def test_start_next_round(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
5 changes: 5 additions & 0 deletions backend/tests/integration_tests/api/clubs_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from bracket.models.db.user_x_club import UserXClubInsertable, UserXClubRelation
from bracket.sql.clubs import get_clubs_for_user_id, sql_delete_club
from bracket.utils.dummy_records import DUMMY_CLUB, DUMMY_MOCK_TIME
Expand All @@ -7,6 +9,7 @@
from tests.integration_tests.sql import inserted_club, inserted_user_x_club


@pytest.mark.asyncio(loop_scope="session")
async def test_clubs_endpoint(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -21,6 +24,7 @@ async def test_clubs_endpoint(
}


@pytest.mark.asyncio(loop_scope="session")
async def test_create_club(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -37,6 +41,7 @@ async def test_create_club(
assert response["data"]["name"] == payload["name"]


@pytest.mark.asyncio(loop_scope="session")
async def test_delete_club(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/integration_tests/api/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# pylint: disable=redefined-outer-name
from collections.abc import AsyncIterator

import pytest
import pytest_asyncio

from tests.integration_tests.api.shared import UvicornTestServer


@pytest.fixture(scope="module")
@pytest_asyncio.fixture(loop_scope="session", scope="module", autouse=True)
async def startup_and_shutdown_uvicorn_server() -> AsyncIterator[None]:
"""
Start server as test fixture and tear down after test
Expand Down
6 changes: 6 additions & 0 deletions backend/tests/integration_tests/api/courts_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from bracket.database import database
from bracket.models.db.court import Court
from bracket.schema import courts
Expand All @@ -9,6 +11,7 @@
from tests.integration_tests.sql import assert_row_count_and_clear, inserted_court, inserted_team


@pytest.mark.asyncio(loop_scope="session")
async def test_courts_endpoint(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -30,6 +33,7 @@ async def test_courts_endpoint(
}


@pytest.mark.asyncio(loop_scope="session")
async def test_create_court(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -39,6 +43,7 @@ async def test_create_court(
await assert_row_count_and_clear(courts, 1)


@pytest.mark.asyncio(loop_scope="session")
async def test_delete_court(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -57,6 +62,7 @@ async def test_delete_court(
await assert_row_count_and_clear(courts, 0)


@pytest.mark.asyncio(loop_scope="session")
async def test_update_court(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
5 changes: 5 additions & 0 deletions backend/tests/integration_tests/api/inputs_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from bracket.models.db.stage_item_inputs import StageItemInputInsertable
from bracket.utils.dummy_records import (
DUMMY_STAGE1,
Expand All @@ -17,6 +19,7 @@
)


@pytest.mark.asyncio(loop_scope="session")
async def test_available_inputs(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -40,6 +43,7 @@ async def test_available_inputs(
}


@pytest.mark.asyncio(loop_scope="session")
async def test_update_stage_item_input(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down Expand Up @@ -74,6 +78,7 @@ async def test_update_stage_item_input(
assert response == {"success": True}


@pytest.mark.asyncio(loop_scope="session")
async def test_update_stage_item_input_invalid_team(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
7 changes: 7 additions & 0 deletions backend/tests/integration_tests/api/matches_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from decimal import Decimal

import pytest

from bracket.database import database
from bracket.models.db.match import Match
from bracket.models.db.stage_item import StageType
Expand Down Expand Up @@ -37,6 +39,7 @@
)


@pytest.mark.asyncio(loop_scope="session")
async def test_create_match(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down Expand Up @@ -82,6 +85,7 @@ async def test_create_match(
await assert_row_count_and_clear(matches, 1)


@pytest.mark.asyncio(loop_scope="session")
async def test_delete_match(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down Expand Up @@ -148,6 +152,7 @@ async def test_delete_match(
await assert_row_count_and_clear(matches, 0)


@pytest.mark.asyncio(loop_scope="session")
async def test_update_match(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down Expand Up @@ -227,6 +232,7 @@ async def test_update_match(
await assert_row_count_and_clear(matches, 1)


@pytest.mark.asyncio(loop_scope="session")
async def test_update_endpoint_custom_duration_margin(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down Expand Up @@ -306,6 +312,7 @@ async def test_update_endpoint_custom_duration_margin(
await assert_row_count_and_clear(matches, 1)


@pytest.mark.asyncio(loop_scope="session")
async def test_upcoming_matches_endpoint(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
3 changes: 3 additions & 0 deletions backend/tests/integration_tests/api/metrics_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest

from bracket.utils.http import HTTPMethod
from tests.integration_tests.api.shared import send_request_raw


@pytest.mark.asyncio(loop_scope="session")
async def test_metrics_endpoint(startup_and_shutdown_uvicorn_server: None) -> None:
text_response = await send_request_raw(HTTPMethod.GET, "metrics")
assert "HELP bracket_response_time" in text_response
3 changes: 3 additions & 0 deletions backend/tests/integration_tests/api/ping_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import pytest

from bracket.utils.http import HTTPMethod
from tests.integration_tests.api.shared import send_request


@pytest.mark.asyncio(loop_scope="session")
async def test_ping_endpoint(startup_and_shutdown_uvicorn_server: None) -> None:
assert await send_request(HTTPMethod.GET, "ping") == "ping"
7 changes: 7 additions & 0 deletions backend/tests/integration_tests/api/players_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from bracket.database import database
from bracket.models.db.player import Player
from bracket.schema import players
Expand All @@ -9,6 +11,7 @@
from tests.integration_tests.sql import assert_row_count_and_clear, inserted_player, inserted_team


@pytest.mark.asyncio(loop_scope="session")
async def test_players_endpoint(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down Expand Up @@ -39,6 +42,7 @@ async def test_players_endpoint(
}


@pytest.mark.asyncio(loop_scope="session")
async def test_create_player(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -48,6 +52,7 @@ async def test_create_player(
await assert_row_count_and_clear(players, 1)


@pytest.mark.asyncio(loop_scope="session")
async def test_create_players(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -59,6 +64,7 @@ async def test_create_players(
await assert_row_count_and_clear(players, 2)


@pytest.mark.asyncio(loop_scope="session")
async def test_delete_player(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -77,6 +83,7 @@ async def test_delete_player(
await assert_row_count_and_clear(players, 0)


@pytest.mark.asyncio(loop_scope="session")
async def test_update_player(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
6 changes: 6 additions & 0 deletions backend/tests/integration_tests/api/rankings_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from decimal import Decimal
from unittest.mock import ANY

import pytest

from bracket.database import database
from bracket.models.db.ranking import Ranking
from bracket.schema import rankings
Expand All @@ -16,6 +18,7 @@
from tests.integration_tests.sql import inserted_ranking, inserted_team


@pytest.mark.asyncio(loop_scope="session")
async def test_rankings_endpoint(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -38,6 +41,7 @@ async def test_rankings_endpoint(
}


@pytest.mark.asyncio(loop_scope="session")
async def test_create_ranking(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -50,6 +54,7 @@ async def test_create_ranking(
await sql_delete_ranking(tournament_id, ranking.id)


@pytest.mark.asyncio(loop_scope="session")
async def test_delete_ranking(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand All @@ -67,6 +72,7 @@ async def test_delete_ranking(
)


@pytest.mark.asyncio(loop_scope="session")
async def test_update_ranking(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from bracket.models.db.match import MatchRescheduleBody
from bracket.models.db.stage_item_inputs import StageItemInputInsertable
from bracket.schema import matches
Expand Down Expand Up @@ -27,6 +29,7 @@
)


@pytest.mark.asyncio(loop_scope="session")
async def test_reschedule_match(
startup_and_shutdown_uvicorn_server: None, auth_context: AuthContext
) -> None:
Expand Down
Loading