Spaces:
Paused
Paused
github-actions[bot] commited on
Commit ·
6437539
1
Parent(s): 7bf5a7e
Automated Deploy: bc9f9bdebdd9f5ac1fd6eca496428aa61a69a2cc
Browse files- AI-coach-agent/docs/SWING_REPORT_API.md +1 -1
- backend/app/core/config.py +1 -2
- backend/app/core/errors.py +1 -1
- backend/app/modules/billing/entitlement.py +5 -1
- backend/docs/FRONTEND_INTEGRATION.md +2 -2
- backend/e2e/qa_accounts_teams.py +2 -2
- backend/e2e/qa_coach_loop.py +1 -1
- backend/e2e/qa_sessions_reports.py +35 -14
- backend/tests/integration/test_accounts.py +2 -2
- backend/tests/integration/test_billing.py +1 -1
- backend/tests/integration/test_sessions.py +13 -8
- backend/tests/integration/test_swing_reports.py +3 -2
AI-coach-agent/docs/SWING_REPORT_API.md
CHANGED
|
@@ -329,7 +329,7 @@ Errors use the backend's single error envelope. `fields` maps each payload path
|
|
| 329 |
| HTTP | `error.code` | When |
|
| 330 |
|---|---|---|
|
| 331 |
| 401 | `UNAUTHENTICATED` | The access token is missing or expired. |
|
| 332 |
-
| 402 | `PLAN_LIMIT` | The free plan's
|
| 333 |
| 403 | `FORBIDDEN` | The session belongs to someone else. |
|
| 334 |
| 404 | `NOT_FOUND` | The session does not exist or was deleted. |
|
| 335 |
| 409 | `STALE_REVISION` | The payload is an older revision than one already reported on. |
|
|
|
|
| 329 |
| HTTP | `error.code` | When |
|
| 330 |
|---|---|---|
|
| 331 |
| 401 | `UNAUTHENTICATED` | The access token is missing or expired. |
|
| 332 |
+
| 402 | `PLAN_LIMIT` | The free plan's 20 analyses this week are used up. |
|
| 333 |
| 403 | `FORBIDDEN` | The session belongs to someone else. |
|
| 334 |
| 404 | `NOT_FOUND` | The session does not exist or was deleted. |
|
| 335 |
| 409 | `STALE_REVISION` | The payload is an older revision than one already reported on. |
|
backend/app/core/config.py
CHANGED
|
@@ -55,8 +55,7 @@ class Settings(BaseSettings):
|
|
| 55 |
require_analysis_consent: bool = False
|
| 56 |
consent_versions: list[str] = ["1.0"]
|
| 57 |
|
| 58 |
-
# Plans
|
| 59 |
-
free_weekly_limit: int = 3
|
| 60 |
entitlement_window_days: int = 7
|
| 61 |
|
| 62 |
# Retention (cleanup job)
|
|
|
|
| 55 |
require_analysis_consent: bool = False
|
| 56 |
consent_versions: list[str] = ["1.0"]
|
| 57 |
|
| 58 |
+
# Plans (the free weekly limit is a fixed constant in app.modules.billing.entitlement, not a setting)
|
|
|
|
| 59 |
entitlement_window_days: int = 7
|
| 60 |
|
| 61 |
# Retention (cleanup job)
|
backend/app/core/errors.py
CHANGED
|
@@ -37,7 +37,7 @@ class Unauthenticated(AppError):
|
|
| 37 |
|
| 38 |
|
| 39 |
class PlanLimitReached(AppError):
|
| 40 |
-
status_code, code, message = 402, "PLAN_LIMIT", "The free plan includes
|
| 41 |
|
| 42 |
|
| 43 |
class Forbidden(AppError):
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
class PlanLimitReached(AppError):
|
| 40 |
+
status_code, code, message = 402, "PLAN_LIMIT", "The free plan includes 20 analyses a week."
|
| 41 |
|
| 42 |
|
| 43 |
class Forbidden(AppError):
|
backend/app/modules/billing/entitlement.py
CHANGED
|
@@ -17,6 +17,10 @@ from app.core.errors import PlanLimitReached
|
|
| 17 |
from app.modules.billing.models import Subscription
|
| 18 |
from app.modules.sessions.models import SwingSession
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
class Entitlement(ResponseModel):
|
| 22 |
plan: str
|
|
@@ -46,7 +50,7 @@ class EntitlementService:
|
|
| 46 |
if await self.is_pro(account_id):
|
| 47 |
return Entitlement(plan="pro", weekly_limit=None, used_this_week=used, left=None,
|
| 48 |
window_days=settings.entitlement_window_days)
|
| 49 |
-
limit =
|
| 50 |
return Entitlement(plan="free", weekly_limit=limit, used_this_week=used, left=max(0, limit - used),
|
| 51 |
window_days=settings.entitlement_window_days)
|
| 52 |
|
|
|
|
| 17 |
from app.modules.billing.models import Subscription
|
| 18 |
from app.modules.sessions.models import SwingSession
|
| 19 |
|
| 20 |
+
# Analyses a free account gets per window. Fixed in code on purpose: no environment variable can change it.
|
| 21 |
+
# The 402 message in app.core.errors.PlanLimitReached states the same number.
|
| 22 |
+
FREE_WEEKLY_LIMIT = 20
|
| 23 |
+
|
| 24 |
|
| 25 |
class Entitlement(ResponseModel):
|
| 26 |
plan: str
|
|
|
|
| 50 |
if await self.is_pro(account_id):
|
| 51 |
return Entitlement(plan="pro", weekly_limit=None, used_this_week=used, left=None,
|
| 52 |
window_days=settings.entitlement_window_days)
|
| 53 |
+
limit = FREE_WEEKLY_LIMIT
|
| 54 |
return Entitlement(plan="free", weekly_limit=limit, used_this_week=used, left=max(0, limit - used),
|
| 55 |
window_days=settings.entitlement_window_days)
|
| 56 |
|
backend/docs/FRONTEND_INTEGRATION.md
CHANGED
|
@@ -82,7 +82,7 @@ All endpoints except `/v1/auth/*` (other than logout) need it.
|
|
| 82 |
| 401 | `INVALID_CREDENTIALS` | Login | Show the message |
|
| 83 |
| 401 | `TOKEN_REVOKED` | Refresh | Sign out |
|
| 84 |
| 401 | `INVALID_TOKEN` | Social sign-in | "Sign-in failed, try again" |
|
| 85 |
-
| 402 | `PLAN_LIMIT` | Create session, swing report | Show the upgrade alert. The message is "The free plan includes
|
| 86 |
| 403 | `FORBIDDEN` | Any | Not allowed. Coach endpoints called by a player, someone else's session, and so on. |
|
| 87 |
| 404 | `NOT_FOUND` | Any | "This session is gone" and similar |
|
| 88 |
| 404 | `TEAM_NOT_FOUND` | Lookup, join | Show the message |
|
|
@@ -162,7 +162,7 @@ The app calls the ML API itself. Our backend never calls the ML API: the app for
|
|
| 162 |
- **Athlete:**
|
| 163 |
- For `is_self: true`, send `athlete: null`; the server snapshots the profile.
|
| 164 |
- For someone else's swing, send `{name, age, height_cm, weight_kg, bats, throws, level}`; all are required.
|
| 165 |
-
- **Plan:** the free plan allows
|
| 166 |
- **No polling:** the Analyzing screen waits on steps 4 and 5. There is no `queued` or `processing` status: a session is `pending` until its report exists, then `done`.
|
| 167 |
- **Pitching:** for a `mode:"p"` session, step 5 is `POST /v1/sessions/{id}/pitch-report` with the ML pitch payload (contract `pitch-1.1`, see `AI-coach-agent/docs/PITCH_REPORT_API.md`). It returns the pitching report, with the groups `gather`, `stride_plant`, `rotation_release` and `release_finish`, and the same revision, plan and consent rules. Posting to the wrong endpoint for the session mode returns 422 `MODE_NOT_SUPPORTED`. The throwing side comes from the payload's `athlete.throwing_hand`, then the session athlete's `throws`.
|
| 168 |
- **Re-analysis:** post a payload with a higher `analysis_revision` and the same `analysis_id`.
|
|
|
|
| 82 |
| 401 | `INVALID_CREDENTIALS` | Login | Show the message |
|
| 83 |
| 401 | `TOKEN_REVOKED` | Refresh | Sign out |
|
| 84 |
| 401 | `INVALID_TOKEN` | Social sign-in | "Sign-in failed, try again" |
|
| 85 |
+
| 402 | `PLAN_LIMIT` | Create session, swing report | Show the upgrade alert. The message is "The free plan includes 20 analyses a week." |
|
| 86 |
| 403 | `FORBIDDEN` | Any | Not allowed. Coach endpoints called by a player, someone else's session, and so on. |
|
| 87 |
| 404 | `NOT_FOUND` | Any | "This session is gone" and similar |
|
| 88 |
| 404 | `TEAM_NOT_FOUND` | Lookup, join | Show the message |
|
|
|
|
| 162 |
- **Athlete:**
|
| 163 |
- For `is_self: true`, send `athlete: null`; the server snapshots the profile.
|
| 164 |
- For someone else's swing, send `{name, age, height_cm, weight_kg, bats, throws, level}`; all are required.
|
| 165 |
+
- **Plan:** the free plan allows 20 analysed swings in a rolling 7 days, counting swings filmed for someone else. Step 3 returns 402 `PLAN_LIMIT` before anything is stored. Pending sessions that never get a report don't count, and are deleted with their media after 24 h.
|
| 166 |
- **No polling:** the Analyzing screen waits on steps 4 and 5. There is no `queued` or `processing` status: a session is `pending` until its report exists, then `done`.
|
| 167 |
- **Pitching:** for a `mode:"p"` session, step 5 is `POST /v1/sessions/{id}/pitch-report` with the ML pitch payload (contract `pitch-1.1`, see `AI-coach-agent/docs/PITCH_REPORT_API.md`). It returns the pitching report, with the groups `gather`, `stride_plant`, `rotation_release` and `release_finish`, and the same revision, plan and consent rules. Posting to the wrong endpoint for the session mode returns 422 `MODE_NOT_SUPPORTED`. The throwing side comes from the payload's `athlete.throwing_hand`, then the session athlete's `throws`.
|
| 168 |
- **Re-analysis:** post a payload with a higher `analysis_revision` and the same `analysis_id`.
|
backend/e2e/qa_accounts_teams.py
CHANGED
|
@@ -307,7 +307,7 @@ def t_me(P: dict):
|
|
| 307 |
e = b["entitlement"]
|
| 308 |
if b["team"] is not None:
|
| 309 |
return "team should be null"
|
| 310 |
-
if e.get("plan") != "free" or e.get("left") !=
|
| 311 |
return f"entitlement {e}"
|
| 312 |
return snake_and_no_secrets(b)
|
| 313 |
expect("GET /me -> user, team null, free 3 left", call("GET", "/v1/me", token=P["access"]), 200, check=check)
|
|
@@ -559,7 +559,7 @@ def t_devices(A: dict, B: dict):
|
|
| 559 |
def t_billing(A: dict):
|
| 560 |
tok = A["access"]
|
| 561 |
expect("GET /me/entitlement free", call("GET", "/v1/me/entitlement", token=tok), 200,
|
| 562 |
-
check=lambda b: None if b == {"plan": "free", "weekly_limit":
|
| 563 |
"window_days": b.get("window_days")} else b)
|
| 564 |
r = call("POST", "/v1/billing/receipts", token=tok,
|
| 565 |
body={"platform": "ios", "product_id": "pro_lifetime_free", "signed_transaction": "x"})
|
|
|
|
| 307 |
e = b["entitlement"]
|
| 308 |
if b["team"] is not None:
|
| 309 |
return "team should be null"
|
| 310 |
+
if e.get("plan") != "free" or e.get("left") != 20 or e.get("used_this_week") != 0 or e.get("weekly_limit") != 20:
|
| 311 |
return f"entitlement {e}"
|
| 312 |
return snake_and_no_secrets(b)
|
| 313 |
expect("GET /me -> user, team null, free 3 left", call("GET", "/v1/me", token=P["access"]), 200, check=check)
|
|
|
|
| 559 |
def t_billing(A: dict):
|
| 560 |
tok = A["access"]
|
| 561 |
expect("GET /me/entitlement free", call("GET", "/v1/me/entitlement", token=tok), 200,
|
| 562 |
+
check=lambda b: None if b == {"plan": "free", "weekly_limit": 20, "used_this_week": 0, "left": 20,
|
| 563 |
"window_days": b.get("window_days")} else b)
|
| 564 |
r = call("POST", "/v1/billing/receipts", token=tok,
|
| 565 |
body={"platform": "ios", "product_id": "pro_lifetime_free", "signed_transaction": "x"})
|
backend/e2e/qa_coach_loop.py
CHANGED
|
@@ -227,7 +227,7 @@ def run():
|
|
| 227 |
r = call("POST", f"/v1/teams/{code.lower()}/join", p["token"])
|
| 228 |
check(f"{p['name']} joins team (lowercased code)", r.status_code == 200, r)
|
| 229 |
|
| 230 |
-
# Sessions. Free plan =
|
| 231 |
p1_a = make_session(p1, tag="p1a") # oldest open
|
| 232 |
p2_a = make_session(p2, tag="p2a")
|
| 233 |
p1_b = make_session(p1, tag="p1b") # P1 newest self
|
|
|
|
| 227 |
r = call("POST", f"/v1/teams/{code.lower()}/join", p["token"])
|
| 228 |
check(f"{p['name']} joins team (lowercased code)", r.status_code == 200, r)
|
| 229 |
|
| 230 |
+
# Sessions. Free plan = 20 analyses/week/owner.
|
| 231 |
p1_a = make_session(p1, tag="p1a") # oldest open
|
| 232 |
p2_a = make_session(p2, tag="p2a")
|
| 233 |
p1_b = make_session(p1, tag="p1b") # P1 newest self
|
backend/e2e/qa_sessions_reports.py
CHANGED
|
@@ -375,8 +375,8 @@ def run():
|
|
| 375 |
|
| 376 |
r = call("GET", "/v1/me", A["token"])
|
| 377 |
ent0 = r.json().get("entitlement", {}) if r.status_code == 200 else {}
|
| 378 |
-
check("GET /me entitlement starts free
|
| 379 |
-
and ent0.get("used_this_week") == 0 and ent0.get("left") ==
|
| 380 |
|
| 381 |
# ------------------------------------------------------------ 1. uploads
|
| 382 |
r = presign(A, "video")
|
|
@@ -697,25 +697,46 @@ def run():
|
|
| 697 |
# ------------------------------------------------------------ 6. plan limit
|
| 698 |
r = call("GET", "/v1/me", A["token"])
|
| 699 |
ent = r.json().get("entitlement", {})
|
| 700 |
-
check("entitlement used 3, left
|
| 701 |
-
ent.get("used_this_week") == 3 and ent.get("left") ==
|
| 702 |
r = call("GET", "/v1/me/entitlement", A["token"])
|
| 703 |
check("GET /me/entitlement matches", r.status_code == 200 and (r.json().get("entitlement", r.json()).get("left")
|
| 704 |
-
==
|
| 705 |
-
v4 = uploaded(A, "video")
|
| 706 |
-
r = call("POST", "/v1/sessions", A["token"], json=session_body(v4["upload_id"]))
|
| 707 |
-
expect_error("4th session in a week on free -> 402 PLAN_LIMIT", r, 402, "PLAN_LIMIT")
|
| 708 |
-
check("402 message is the app's text", (r.json().get("error") or {}).get("message")
|
| 709 |
-
== "The free plan includes 3 analyses a week.", r)
|
| 710 |
-
if S_else:
|
| 711 |
-
expect_error("reporting a pending session after the limit -> 402 PLAN_LIMIT",
|
| 712 |
-
post_report(A, S_else["id"], payload(hand="left", lead="right")), 402, "PLAN_LIMIT")
|
| 713 |
if S1:
|
| 714 |
r = post_report(A, S1["id"], payload(sep=-15, analysis_id=rep1["analysis_id"], rev=3))
|
| 715 |
-
check("a new revision on an already analysed session
|
| 716 |
if r.status_code == 200:
|
| 717 |
rep1 = r.json()
|
| 718 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 719 |
# ------------------------------------------------------------ left-handed hitter (B, someone else's swing)
|
| 720 |
LB = new_session(B, "B someone else, left-handed college", is_self=False, athlete={
|
| 721 |
"name": "Lefty Lou", "age": 20, "height_cm": 180, "weight_kg": 80, "bats": "L", "throws": "L",
|
|
|
|
| 375 |
|
| 376 |
r = call("GET", "/v1/me", A["token"])
|
| 377 |
ent0 = r.json().get("entitlement", {}) if r.status_code == 200 else {}
|
| 378 |
+
check("GET /me entitlement starts free 20/0", ent0.get("plan") == "free" and ent0.get("weekly_limit") == 20
|
| 379 |
+
and ent0.get("used_this_week") == 0 and ent0.get("left") == 20, r, json.dumps(ent0))
|
| 380 |
|
| 381 |
# ------------------------------------------------------------ 1. uploads
|
| 382 |
r = presign(A, "video")
|
|
|
|
| 697 |
# ------------------------------------------------------------ 6. plan limit
|
| 698 |
r = call("GET", "/v1/me", A["token"])
|
| 699 |
ent = r.json().get("entitlement", {})
|
| 700 |
+
check("entitlement used 3, left 17 (pending sessions S_else, S_p not counted)",
|
| 701 |
+
ent.get("used_this_week") == 3 and ent.get("left") == 17, r, json.dumps(ent))
|
| 702 |
r = call("GET", "/v1/me/entitlement", A["token"])
|
| 703 |
check("GET /me/entitlement matches", r.status_code == 200 and (r.json().get("entitlement", r.json()).get("left")
|
| 704 |
+
== 17), r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 705 |
if S1:
|
| 706 |
r = post_report(A, S1["id"], payload(sep=-15, analysis_id=rep1["analysis_id"], rev=3))
|
| 707 |
+
check("a new revision on an already analysed session works", r.status_code == 200, r)
|
| 708 |
if r.status_code == 200:
|
| 709 |
rep1 = r.json()
|
| 710 |
|
| 711 |
+
# The limit itself runs on its own account, so A's sessions stay as the list checks below expect.
|
| 712 |
+
L = register()
|
| 713 |
+
set_profile(L, name="QA Limit", age=20, height_cm=183, weight_kg=85, bats="R", throws="R", level="college")
|
| 714 |
+
L_pending = new_session(L, "limit: pending, created before the limit", with_thumb=False)
|
| 715 |
+
L_first, L_first_rep, analysed = None, None, 0
|
| 716 |
+
for i in range(1, 21):
|
| 717 |
+
s = new_session(L, f"limit: analysed #{i}", with_thumb=False)
|
| 718 |
+
r = post_report(L, s["id"], payload()) if s else None
|
| 719 |
+
if r is not None and r.status_code == 200:
|
| 720 |
+
analysed += 1
|
| 721 |
+
if L_first is None:
|
| 722 |
+
L_first, L_first_rep = s, r.json()
|
| 723 |
+
check("20 analyses in a week are allowed on free", analysed == 20, None, f"analysed={analysed}")
|
| 724 |
+
r = call("GET", "/v1/me/entitlement", L["token"])
|
| 725 |
+
ent = r.json().get("entitlement", r.json()) if r.status_code == 200 else {}
|
| 726 |
+
check("entitlement used 20, left 0 (the pending session is not counted)", ent.get("weekly_limit") == 20
|
| 727 |
+
and ent.get("used_this_week") == 20 and ent.get("left") == 0, r, json.dumps(ent))
|
| 728 |
+
v21 = uploaded(L, "video")
|
| 729 |
+
r = call("POST", "/v1/sessions", L["token"], json=session_body(v21["upload_id"]))
|
| 730 |
+
expect_error("21st session in a week on free -> 402 PLAN_LIMIT", r, 402, "PLAN_LIMIT")
|
| 731 |
+
check("402 message is the app's text", (r.json().get("error") or {}).get("message")
|
| 732 |
+
== "The free plan includes 20 analyses a week.", r)
|
| 733 |
+
if L_pending:
|
| 734 |
+
expect_error("reporting a pending session after the limit -> 402 PLAN_LIMIT",
|
| 735 |
+
post_report(L, L_pending["id"], payload()), 402, "PLAN_LIMIT")
|
| 736 |
+
if L_first:
|
| 737 |
+
r = post_report(L, L_first["id"], payload(sep=-15, analysis_id=L_first_rep["analysis_id"], rev=2))
|
| 738 |
+
check("a new revision on an already analysed session still works at the limit", r.status_code == 200, r)
|
| 739 |
+
|
| 740 |
# ------------------------------------------------------------ left-handed hitter (B, someone else's swing)
|
| 741 |
LB = new_session(B, "B someone else, left-handed college", is_self=False, athlete={
|
| 742 |
"name": "Lefty Lou", "age": 20, "height_cm": 180, "weight_kg": 80, "bats": "L", "throws": "L",
|
backend/tests/integration/test_accounts.py
CHANGED
|
@@ -52,7 +52,7 @@ async def test_me_without_team(client):
|
|
| 52 |
body = response.json()
|
| 53 |
assert body["user"] == account["user"]
|
| 54 |
assert body["team"] is None
|
| 55 |
-
assert body["entitlement"] == {"plan": "free", "weekly_limit":
|
| 56 |
"window_days": 7}
|
| 57 |
|
| 58 |
|
|
@@ -79,7 +79,7 @@ async def test_me_counts_usage(client):
|
|
| 79 |
account = await register(client)
|
| 80 |
await _make_session(account["user"]["id"])
|
| 81 |
entitlement = (await client.get("/v1/me", headers=account["headers"])).json()["entitlement"]
|
| 82 |
-
assert entitlement["used_this_week"] == 1 and entitlement["left"] ==
|
| 83 |
|
| 84 |
|
| 85 |
@pytest.mark.parametrize("headers", [{}, bearer("not-a-jwt")])
|
|
|
|
| 52 |
body = response.json()
|
| 53 |
assert body["user"] == account["user"]
|
| 54 |
assert body["team"] is None
|
| 55 |
+
assert body["entitlement"] == {"plan": "free", "weekly_limit": 20, "used_this_week": 0, "left": 20,
|
| 56 |
"window_days": 7}
|
| 57 |
|
| 58 |
|
|
|
|
| 79 |
account = await register(client)
|
| 80 |
await _make_session(account["user"]["id"])
|
| 81 |
entitlement = (await client.get("/v1/me", headers=account["headers"])).json()["entitlement"]
|
| 82 |
+
assert entitlement["used_this_week"] == 1 and entitlement["left"] == 19
|
| 83 |
|
| 84 |
|
| 85 |
@pytest.mark.parametrize("headers", [{}, bearer("not-a-jwt")])
|
backend/tests/integration/test_billing.py
CHANGED
|
@@ -116,7 +116,7 @@ async def test_entitlement_free_then_pro(client):
|
|
| 116 |
account_id, headers = await _account()
|
| 117 |
response = await client.get("/v1/me/entitlement", headers=headers)
|
| 118 |
assert response.status_code == 200
|
| 119 |
-
assert response.json() == {"plan": "free", "weekly_limit":
|
| 120 |
|
| 121 |
await _insert(account_id, otid="old", status="active", expires=EARLIER)
|
| 122 |
assert (await client.get("/v1/me/entitlement", headers=headers)).json()["plan"] == "free"
|
|
|
|
| 116 |
account_id, headers = await _account()
|
| 117 |
response = await client.get("/v1/me/entitlement", headers=headers)
|
| 118 |
assert response.status_code == 200
|
| 119 |
+
assert response.json() == {"plan": "free", "weekly_limit": 20, "used_this_week": 0, "left": 20, "window_days": 7}
|
| 120 |
|
| 121 |
await _insert(account_id, otid="old", status="active", expires=EARLIER)
|
| 122 |
assert (await client.get("/v1/me/entitlement", headers=headers)).json()["plan"] == "free"
|
backend/tests/integration/test_sessions.py
CHANGED
|
@@ -10,6 +10,7 @@ from sqlalchemy import select
|
|
| 10 |
from app.core.config import get_settings
|
| 11 |
from app.core.database import get_session_factory
|
| 12 |
from app.integrations.storage import get_storage
|
|
|
|
| 13 |
from app.modules.reviews.models import Review
|
| 14 |
from app.modules.sessions.models import SwingSession
|
| 15 |
from app.modules.uploads.models import Upload
|
|
@@ -20,6 +21,7 @@ from tests.factories import (
|
|
| 20 |
VIDEO,
|
| 21 |
create_session,
|
| 22 |
make_account,
|
|
|
|
| 23 |
make_team_row,
|
| 24 |
mark_analyzed,
|
| 25 |
session_body,
|
|
@@ -186,25 +188,28 @@ async def test_create_session_upload_invalid_size(client, monkeypatch):
|
|
| 186 |
assert response.json()["error"]["code"] == "UPLOAD_INVALID"
|
| 187 |
|
| 188 |
|
| 189 |
-
async def
|
| 190 |
player = await make_account()
|
| 191 |
h = player["headers"]
|
| 192 |
-
for
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
| 195 |
video_id = await upload(client, h)
|
| 196 |
response = await client.post("/v1/sessions", json=session_body(video_id, None), headers=h)
|
| 197 |
assert response.status_code == 402
|
| 198 |
-
assert response.json()["error"] == {"code": "PLAN_LIMIT", "message": "The free plan includes
|
| 199 |
-
listed = await client.get("/v1/sessions", headers=h)
|
| 200 |
-
assert len(listed.json()["items"]) ==
|
| 201 |
async with get_session_factory()() as db:
|
| 202 |
assert (await db.get(Upload, uuid.UUID(video_id))).attached_at is None
|
| 203 |
|
| 204 |
|
| 205 |
async def test_pending_sessions_do_not_count_toward_the_plan(client):
|
| 206 |
player = await make_account()
|
| 207 |
-
for _ in range(
|
| 208 |
await create_session(client, player["headers"])
|
| 209 |
|
| 210 |
|
|
|
|
| 10 |
from app.core.config import get_settings
|
| 11 |
from app.core.database import get_session_factory
|
| 12 |
from app.integrations.storage import get_storage
|
| 13 |
+
from app.modules.billing.entitlement import FREE_WEEKLY_LIMIT
|
| 14 |
from app.modules.reviews.models import Review
|
| 15 |
from app.modules.sessions.models import SwingSession
|
| 16 |
from app.modules.uploads.models import Upload
|
|
|
|
| 21 |
VIDEO,
|
| 22 |
create_session,
|
| 23 |
make_account,
|
| 24 |
+
make_session,
|
| 25 |
make_team_row,
|
| 26 |
mark_analyzed,
|
| 27 |
session_body,
|
|
|
|
| 188 |
assert response.json()["error"]["code"] == "UPLOAD_INVALID"
|
| 189 |
|
| 190 |
|
| 191 |
+
async def test_plan_limit_after_twenty_analysed_sessions_in_a_week(client):
|
| 192 |
player = await make_account()
|
| 193 |
h = player["headers"]
|
| 194 |
+
for _ in range(FREE_WEEKLY_LIMIT - 1):
|
| 195 |
+
await make_session(player["id"])
|
| 196 |
+
s = await create_session(client, h) # the 20th is still allowed
|
| 197 |
+
await mark_analyzed(s["id"], 60)
|
| 198 |
+
entitlement = (await client.get("/v1/me/entitlement", headers=h)).json()
|
| 199 |
+
assert entitlement == {"plan": "free", "weekly_limit": 20, "used_this_week": 20, "left": 0, "window_days": 7}
|
| 200 |
video_id = await upload(client, h)
|
| 201 |
response = await client.post("/v1/sessions", json=session_body(video_id, None), headers=h)
|
| 202 |
assert response.status_code == 402
|
| 203 |
+
assert response.json()["error"] == {"code": "PLAN_LIMIT", "message": "The free plan includes 20 analyses a week."}
|
| 204 |
+
listed = await client.get("/v1/sessions", headers=h, params={"limit": 50})
|
| 205 |
+
assert len(listed.json()["items"]) == FREE_WEEKLY_LIMIT
|
| 206 |
async with get_session_factory()() as db:
|
| 207 |
assert (await db.get(Upload, uuid.UUID(video_id))).attached_at is None
|
| 208 |
|
| 209 |
|
| 210 |
async def test_pending_sessions_do_not_count_toward_the_plan(client):
|
| 211 |
player = await make_account()
|
| 212 |
+
for _ in range(FREE_WEEKLY_LIMIT + 1):
|
| 213 |
await create_session(client, player["headers"])
|
| 214 |
|
| 215 |
|
backend/tests/integration/test_swing_reports.py
CHANGED
|
@@ -12,6 +12,7 @@ from ai_coach.swing_report import build_report
|
|
| 12 |
|
| 13 |
from app.core.database import get_session_factory
|
| 14 |
from app.core.dependencies import Db
|
|
|
|
| 15 |
from app.modules.sessions.models import SwingSession
|
| 16 |
from app.modules.swing_reports.controller import get_swing_report_service
|
| 17 |
from app.modules.swing_reports.service import SwingReportService
|
|
@@ -263,7 +264,7 @@ async def test_unknown_and_deleted_sessions_not_found(client):
|
|
| 263 |
|
| 264 |
async def test_plan_limit_on_first_analysis_only(client):
|
| 265 |
owner, headers = await make_account()
|
| 266 |
-
for _ in range(
|
| 267 |
await make_session(owner, analyzed_at=datetime.now(UTC), report={"overall_score": 50},
|
| 268 |
analysis_id=uuid.uuid4().hex, analysis_revision=1)
|
| 269 |
sid = await make_session(owner)
|
|
@@ -277,7 +278,7 @@ async def test_rebuild_allowed_at_plan_limit(client):
|
|
| 277 |
owner, headers = await make_account()
|
| 278 |
sid = await make_session(owner)
|
| 279 |
assert (await client.post(url(sid), json=PAYLOAD, headers=headers)).status_code == 200
|
| 280 |
-
for _ in range(
|
| 281 |
await make_session(owner, analyzed_at=datetime.now(UTC), report={"overall_score": 50},
|
| 282 |
analysis_id=uuid.uuid4().hex, analysis_revision=1)
|
| 283 |
response = await client.post(url(sid), json=payload(analysis_revision=2), headers=headers)
|
|
|
|
| 12 |
|
| 13 |
from app.core.database import get_session_factory
|
| 14 |
from app.core.dependencies import Db
|
| 15 |
+
from app.modules.billing.entitlement import FREE_WEEKLY_LIMIT
|
| 16 |
from app.modules.sessions.models import SwingSession
|
| 17 |
from app.modules.swing_reports.controller import get_swing_report_service
|
| 18 |
from app.modules.swing_reports.service import SwingReportService
|
|
|
|
| 264 |
|
| 265 |
async def test_plan_limit_on_first_analysis_only(client):
|
| 266 |
owner, headers = await make_account()
|
| 267 |
+
for _ in range(FREE_WEEKLY_LIMIT):
|
| 268 |
await make_session(owner, analyzed_at=datetime.now(UTC), report={"overall_score": 50},
|
| 269 |
analysis_id=uuid.uuid4().hex, analysis_revision=1)
|
| 270 |
sid = await make_session(owner)
|
|
|
|
| 278 |
owner, headers = await make_account()
|
| 279 |
sid = await make_session(owner)
|
| 280 |
assert (await client.post(url(sid), json=PAYLOAD, headers=headers)).status_code == 200
|
| 281 |
+
for _ in range(FREE_WEEKLY_LIMIT - 1):
|
| 282 |
await make_session(owner, analyzed_at=datetime.now(UTC), report={"overall_score": 50},
|
| 283 |
analysis_id=uuid.uuid4().hex, analysis_revision=1)
|
| 284 |
response = await client.post(url(sid), json=payload(analysis_revision=2), headers=headers)
|