/
pa1ch
/
FitAssistant
Обзор
Документация
Войти
/
pa1ch
/
FitAssistant
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/integration/api/test_users.py
120 строк
4 KB
Pavel Chugaev
feat(ai): контекст спортсмена во всех AI-запросах + заметка для ИИ в профиле
15 июл 2026, 23:33
15 июл 2026, 23:33
d6d4ba3
Код
Авторство
О чём код?
async def test_get_me(client): resp = await client.get("/api/v1/users/me") assert resp.status_code == 200 data = resp.json() assert data["name"] == "TestUser" async def test_patch_me(client): resp = await client.patch( "/api/v1/users/me", json={"name": "NewName", "utc_offset_hours": 3.0}, ) assert resp.status_code == 200 data = resp.json() assert data["name"] == "NewName" assert data["utc_offset_hours"] == 3.0 async def test_patch_me_partial(client): resp = await client.patch( "/api/v1/users/me", json={"remind_workout_days": 5}, ) assert resp.status_code == 200 data = resp.json() assert data["remind_workout_days"] == 5 assert data["name"] == "TestUser" # unchanged # --- POST /users/me/onboarding --- _ATHLETE_BODY = { "role": "athlete", "fitness_goal": "gain_mass", "sex": "male", "birth_year": 1995, "height_cm": 180, "weight_kg": 80, "experience_level": "intermediate", } async def test_onboarding_athlete(client): resp = await client.post("/api/v1/users/me/onboarding", json=_ATHLETE_BODY) assert resp.status_code == 200 data = resp.json() assert data["onboarding_done"] is True assert data["fitness_goal"] == "gain_mass" assert data["height_cm"] == 180 assert data["is_coach"] is False async def test_onboarding_coach_fills_same_profile(client): # A coach fills the same profile as an athlete and additionally gets is_coach. resp = await client.post("/api/v1/users/me/onboarding", json={**_ATHLETE_BODY, "role": "coach"}) assert resp.status_code == 200 data = resp.json() assert data["onboarding_done"] is True assert data["is_coach"] is True assert data["fitness_goal"] == "gain_mass" async def test_onboarding_coach_requires_profile(client): # No coach-only path anymore: a coach must provide the profile fields. resp = await client.post("/api/v1/users/me/onboarding", json={"role": "coach"}) assert resp.status_code == 400 async def test_onboarding_bad_birth_year(client): body = {**_ATHLETE_BODY, "birth_year": 1800} resp = await client.post("/api/v1/users/me/onboarding", json=body) assert resp.status_code == 400 async def test_onboarding_unknown_role(client): resp = await client.post("/api/v1/users/me/onboarding", json={"role": "ninja"}) assert resp.status_code == 400 async def test_onboarding_invalid_enum(client): body = {**_ATHLETE_BODY, "fitness_goal": "fly_to_mars"} resp = await client.post("/api/v1/users/me/onboarding", json=body) assert resp.status_code == 400 async def test_onboarding_idempotent(client): first = await client.post("/api/v1/users/me/onboarding", json=_ATHLETE_BODY) assert first.status_code == 200 second = await client.post("/api/v1/users/me/onboarding", json=_ATHLETE_BODY) assert second.status_code == 200 assert second.json()["onboarding_done"] is True # --- AI context (профиль для ИИ-тренера) --- async def test_patch_ai_profile_note_and_context(client): resp = await client.patch( "/api/v1/users/me", json={"ai_profile_note": "болит колено", "sex": "female"}, ) assert resp.status_code == 200 assert resp.json()["ai_profile_note"] == "болит колено" resp = await client.get("/api/v1/users/me/ai-context") assert resp.status_code == 200 context = resp.json()["context"] assert "Спортсменка" in context assert "болит колено" in context async def test_ai_context_empty_profile(client): resp = await client.get("/api/v1/users/me/ai-context") assert resp.status_code == 200 assert resp.json()["context"] == "" async def test_ai_profile_note_too_long_rejected(client): resp = await client.patch("/api/v1/users/me", json={"ai_profile_note": "x" * 1001}) assert resp.status_code == 422