[Eva] test_smoke: hint → show-answer (medium/hard/easy)

This commit is contained in:
2026-10-26 17:54:56 +00:00
parent 361e2d9b61
commit 17f7ed7370
+68 -27
View File
@@ -1966,44 +1966,85 @@ async def test_sentences_stats(smoke_user):
assert passed
async def test_sentences_hint(smoke_user, smoke_conn):
"""GET /sentences/{id}/hint → sentence_pl, лимит 1 раз."""
async def test_sentences_show_answer_medium(smoke_user, smoke_conn):
"""POST /sentences/show-answer — Medium: лимит 2 (200, 200, 403)."""
client = smoke_user
# Берём предложение, которое юзер ещё НЕ проходил и НЕ брал подсказку
sentence_id = await smoke_conn.fetchval("""
SELECT id FROM sentences
WHERE id NOT IN (
SELECT sentence_id FROM sentence_hints_used WHERE user_id = $1
await smoke_conn.execute(
"UPDATE users SET difficulty = 'medium' WHERE telegram_id = $1", SMOKE_USER_ID
)
ORDER BY id LIMIT 1
""", SMOKE_USER_ID)
sentence_id = await smoke_conn.fetchval("SELECT id FROM sentences ORDER BY id LIMIT 1")
if not sentence_id:
pytest.skip("Нет предложений для hint-теста")
pytest.skip("Нет предложений для show-answer теста")
return
# 1. Первый запрос — 200
resp1 = await client.get(f"/sentences/{sentence_id}/hint")
ok1 = resp1.status_code == 200
body1 = resp1.json() if ok1 else {}
has_sentence = bool(body1.get("sentence_pl"))
# 2. Проверка в БД
recorded = await smoke_conn.fetchval(
"SELECT 1 FROM sentence_hints_used WHERE user_id = $1 AND sentence_id = $2",
# Чистим list_opened, чтобы начать с 0
await smoke_conn.execute(
"DELETE FROM sentence_progress WHERE user_id = $1 AND sentence_id = $2",
SMOKE_USER_ID, sentence_id,
) is not None
)
# 3. Второй запрос — 403 (лимит)
resp2 = await client.get(f"/sentences/{sentence_id}/hint")
limit_ok = resp2.status_code == 403
resp1 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
resp2 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
resp3 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
passed = ok1 and has_sentence and recorded and limit_ok
passed = resp1.status_code == 200 and resp2.status_code == 200 and resp3.status_code == 403
RESULTS.append(ScenarioResult(
"sentences_hint", "sentences", passed,
f"first={resp1.status_code}, recorded={recorded}, second={resp2.status_code} (ожидали 403)",
{"first_status": resp1.status_code, "recorded": recorded, "second_status": resp2.status_code},
"sentences_show_answer_medium", "sentences", passed,
f"medium: 1={resp1.status_code}, 2={resp2.status_code}, 3={resp3.status_code} (ожидали 200/200/403)",
{"first": resp1.status_code, "second": resp2.status_code, "third": resp3.status_code},
))
assert passed
async def test_sentences_show_answer_hard(smoke_user, smoke_conn):
"""POST /sentences/show-answer — Hard: сразу 403."""
client = smoke_user
await smoke_conn.execute(
"UPDATE users SET difficulty = 'hard' WHERE telegram_id = $1", SMOKE_USER_ID
)
sentence_id = await smoke_conn.fetchval("SELECT id FROM sentences ORDER BY id LIMIT 1")
if not sentence_id:
pytest.skip("Нет предложений для show-answer теста")
return
resp = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
passed = resp.status_code == 403
RESULTS.append(ScenarioResult(
"sentences_show_answer_hard", "sentences", passed,
f"hard: status={resp.status_code} (ожидали 403)",
{"status": resp.status_code},
))
assert passed
async def test_sentences_show_answer_easy(smoke_user, smoke_conn):
"""POST /sentences/show-answer — Easy: без лимита (несколько 200)."""
client = smoke_user
await smoke_conn.execute(
"UPDATE users SET difficulty = 'easy' WHERE telegram_id = $1", SMOKE_USER_ID
)
sentence_id = await smoke_conn.fetchval("SELECT id FROM sentences ORDER BY id LIMIT 1")
if not sentence_id:
pytest.skip("Нет предложений для show-answer теста")
return
statuses = []
for _ in range(3):
r = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
statuses.append(r.status_code)
passed = all(s == 200 for s in statuses)
RESULTS.append(ScenarioResult(
"sentences_show_answer_easy", "sentences", passed,
f"easy: statuses={statuses} (ожидали все 200)",
{"statuses": statuses},
))
assert passed