Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d809590f0e | |||
| 0d8e666a75 | |||
|
|
bd19b7d913 | ||
|
|
c49f91cc19 | ||
|
|
215085b326 | ||
| c063f5c4ef | |||
|
|
d92f571960 |
@ -379,14 +379,14 @@ def update_season_pitching_stats(player_ids, season, db_connection):
|
||||
|
||||
-- RBI allowed (excluding HR) per runner opportunity
|
||||
CASE
|
||||
WHEN (SUM(CASE WHEN sp.on_first IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_second IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_third IS NOT NULL THEN 1 ELSE 0 END)) > 0
|
||||
WHEN (SUM(CASE WHEN sp.on_first_id IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_second_id IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_third_id IS NOT NULL THEN 1 ELSE 0 END)) > 0
|
||||
THEN ROUND(
|
||||
(SUM(sp.rbi) - SUM(sp.homerun))::DECIMAL /
|
||||
(SUM(CASE WHEN sp.on_first IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_second IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_third IS NOT NULL THEN 1 ELSE 0 END)),
|
||||
(SUM(CASE WHEN sp.on_first_id IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_second_id IS NOT NULL THEN 1 ELSE 0 END) +
|
||||
SUM(CASE WHEN sp.on_third_id IS NOT NULL THEN 1 ELSE 0 END)),
|
||||
3
|
||||
)
|
||||
ELSE 0.000
|
||||
@ -807,6 +807,10 @@ def handle_db_errors(func):
|
||||
|
||||
return result
|
||||
|
||||
except HTTPException:
|
||||
# Let intentional HTTP errors (401, 404, etc.) pass through unchanged
|
||||
raise
|
||||
|
||||
except Exception as e:
|
||||
elapsed_time = time.time() - start_time
|
||||
error_trace = traceback.format_exc()
|
||||
|
||||
@ -10,8 +10,6 @@ from ..dependencies import (
|
||||
oauth2_scheme,
|
||||
cache_result,
|
||||
handle_db_errors,
|
||||
MAX_LIMIT,
|
||||
DEFAULT_LIMIT,
|
||||
)
|
||||
from ..services.base import BaseService
|
||||
from ..services.player_service import PlayerService
|
||||
@ -30,7 +28,7 @@ async def get_players(
|
||||
strat_code: list = Query(default=None),
|
||||
is_injured: Optional[bool] = None,
|
||||
sort: Optional[str] = None,
|
||||
limit: int = Query(default=DEFAULT_LIMIT, ge=1, le=MAX_LIMIT),
|
||||
limit: Optional[int] = Query(default=None, ge=1),
|
||||
offset: Optional[int] = Query(
|
||||
default=None, ge=0, description="Number of results to skip for pagination"
|
||||
),
|
||||
|
||||
@ -81,9 +81,9 @@ class TestRouteRegistration:
|
||||
for route, methods in EXPECTED_PLAY_ROUTES.items():
|
||||
assert route in paths, f"Route {route} missing from OpenAPI schema"
|
||||
for method in methods:
|
||||
assert (
|
||||
method in paths[route]
|
||||
), f"Method {method.upper()} missing for {route}"
|
||||
assert method in paths[route], (
|
||||
f"Method {method.upper()} missing for {route}"
|
||||
)
|
||||
|
||||
def test_play_routes_have_plays_tag(self, api):
|
||||
"""All play routes should be tagged with 'plays'."""
|
||||
@ -96,9 +96,9 @@ class TestRouteRegistration:
|
||||
for method, spec in paths[route].items():
|
||||
if method in ("get", "post", "patch", "delete"):
|
||||
tags = spec.get("tags", [])
|
||||
assert (
|
||||
"plays" in tags
|
||||
), f"{method.upper()} {route} missing 'plays' tag, has {tags}"
|
||||
assert "plays" in tags, (
|
||||
f"{method.upper()} {route} missing 'plays' tag, has {tags}"
|
||||
)
|
||||
|
||||
@pytest.mark.post_deploy
|
||||
@pytest.mark.skip(
|
||||
@ -124,9 +124,9 @@ class TestRouteRegistration:
|
||||
]:
|
||||
params = paths[route]["get"].get("parameters", [])
|
||||
param_names = [p["name"] for p in params]
|
||||
assert (
|
||||
"sbaplayer_id" in param_names
|
||||
), f"sbaplayer_id parameter missing from {route}"
|
||||
assert "sbaplayer_id" in param_names, (
|
||||
f"sbaplayer_id parameter missing from {route}"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@ -493,10 +493,9 @@ class TestPlayCrud:
|
||||
assert result["id"] == play_id
|
||||
|
||||
def test_get_nonexistent_play(self, api):
|
||||
"""GET /plays/999999999 returns an error (wrapped by handle_db_errors)."""
|
||||
"""GET /plays/999999999 returns 404 Not Found."""
|
||||
r = requests.get(f"{api}/api/v3/plays/999999999", timeout=10)
|
||||
# handle_db_errors wraps HTTPException as 500 with detail message
|
||||
assert r.status_code == 500
|
||||
assert r.status_code == 404
|
||||
assert "not found" in r.json().get("detail", "").lower()
|
||||
|
||||
|
||||
@ -575,9 +574,9 @@ class TestGroupBySbaPlayer:
|
||||
)
|
||||
assert r_seasons.status_code == 200
|
||||
season_pas = [s["pa"] for s in r_seasons.json()["stats"]]
|
||||
assert career_pa >= max(
|
||||
season_pas
|
||||
), f"Career PA ({career_pa}) should be >= max season PA ({max(season_pas)})"
|
||||
assert career_pa >= max(season_pas), (
|
||||
f"Career PA ({career_pa}) should be >= max season PA ({max(season_pas)})"
|
||||
)
|
||||
|
||||
@pytest.mark.post_deploy
|
||||
def test_batting_sbaplayer_short_output(self, api):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user