[Eva] test_smoke: hint → show-answer (medium/hard/easy)
This commit is contained in:
+68
-27
@@ -1966,44 +1966,85 @@ async def test_sentences_stats(smoke_user):
|
|||||||
assert passed
|
assert passed
|
||||||
|
|
||||||
|
|
||||||
async def test_sentences_hint(smoke_user, smoke_conn):
|
async def test_sentences_show_answer_medium(smoke_user, smoke_conn):
|
||||||
"""GET /sentences/{id}/hint → sentence_pl, лимит 1 раз."""
|
"""POST /sentences/show-answer — Medium: лимит 2 (200, 200, 403)."""
|
||||||
client = smoke_user
|
client = smoke_user
|
||||||
|
|
||||||
# Берём предложение, которое юзер ещё НЕ проходил и НЕ брал подсказку
|
await smoke_conn.execute(
|
||||||
sentence_id = await smoke_conn.fetchval("""
|
"UPDATE users SET difficulty = 'medium' WHERE telegram_id = $1", SMOKE_USER_ID
|
||||||
SELECT id FROM sentences
|
|
||||||
WHERE id NOT IN (
|
|
||||||
SELECT sentence_id FROM sentence_hints_used WHERE user_id = $1
|
|
||||||
)
|
)
|
||||||
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:
|
if not sentence_id:
|
||||||
pytest.skip("Нет предложений для hint-теста")
|
pytest.skip("Нет предложений для show-answer теста")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 1. Первый запрос — 200
|
# Чистим list_opened, чтобы начать с 0
|
||||||
resp1 = await client.get(f"/sentences/{sentence_id}/hint")
|
await smoke_conn.execute(
|
||||||
ok1 = resp1.status_code == 200
|
"DELETE FROM sentence_progress WHERE user_id = $1 AND sentence_id = $2",
|
||||||
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",
|
|
||||||
SMOKE_USER_ID, sentence_id,
|
SMOKE_USER_ID, sentence_id,
|
||||||
) is not None
|
)
|
||||||
|
|
||||||
# 3. Второй запрос — 403 (лимит)
|
resp1 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
|
||||||
resp2 = await client.get(f"/sentences/{sentence_id}/hint")
|
resp2 = await client.post("/sentences/show-answer", json={"sentence_id": sentence_id})
|
||||||
limit_ok = resp2.status_code == 403
|
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(
|
RESULTS.append(ScenarioResult(
|
||||||
"sentences_hint", "sentences", passed,
|
"sentences_show_answer_medium", "sentences", passed,
|
||||||
f"first={resp1.status_code}, recorded={recorded}, second={resp2.status_code} (ожидали 403)",
|
f"medium: 1={resp1.status_code}, 2={resp2.status_code}, 3={resp3.status_code} (ожидали 200/200/403)",
|
||||||
{"first_status": resp1.status_code, "recorded": recorded, "second_status": resp2.status_code},
|
{"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
|
assert passed
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user