forked from retoor/devplacepy
Quiiz system
This commit is contained in:
@@ -145,3 +145,59 @@ def test_restore_revoked_award_recomputes_stats(seeded_db):
|
||||
assert row.get("award_count") == 1
|
||||
assert row.get("last_award_uid") == uid
|
||||
assert requests.get(f"{BASE_URL}/awards/{slug}/256").status_code in (302, 404)
|
||||
|
||||
|
||||
def _create_quiz_trash(session):
|
||||
slug = session.post(
|
||||
f"{BASE_URL}/quizzes/create",
|
||||
headers=JSON_trash,
|
||||
data={"title": _unique_trash("trrquiz"), "description": "restore quiz body"},
|
||||
).json()["data"]["slug"]
|
||||
session.post(
|
||||
f"{BASE_URL}/quizzes/{slug}/questions",
|
||||
headers=JSON_trash,
|
||||
data={
|
||||
"kind": "single_choice",
|
||||
"prompt": "Which journal mode allows concurrent readers?",
|
||||
"points": 2,
|
||||
"options": "DELETE\nWAL",
|
||||
"correct_indexes": "1",
|
||||
},
|
||||
)
|
||||
session.post(f"{BASE_URL}/quizzes/{slug}/publish", headers=JSON_trash)
|
||||
return slug
|
||||
|
||||
|
||||
def test_restore_revives_a_quiz_with_its_whole_cascade(seeded_db):
|
||||
from devplacepy.database import get_table, refresh_snapshot
|
||||
|
||||
author, _ = _member_trash()
|
||||
player, _ = _member_trash()
|
||||
slug = _create_quiz_trash(author)
|
||||
player.post(f"{BASE_URL}/quizzes/{slug}/attempts", headers=JSON_trash)
|
||||
refresh_snapshot()
|
||||
quiz = get_table("quizzes").find_one(slug=slug)
|
||||
|
||||
author.post(f"{BASE_URL}/quizzes/delete/{slug}", headers=JSON_trash, allow_redirects=False)
|
||||
refresh_snapshot()
|
||||
stamps = set()
|
||||
for table in ("quiz_questions", "quiz_options", "quiz_attempts", "quiz_answers"):
|
||||
rows = list(get_table(table).find(quiz_uid=quiz["uid"]))
|
||||
assert rows
|
||||
for row in rows:
|
||||
assert row["deleted_at"]
|
||||
stamps.add(row["deleted_at"])
|
||||
assert len(stamps) == 1
|
||||
|
||||
admin = _admin_trash(seeded_db)
|
||||
response = admin.post(
|
||||
f"{BASE_URL}/admin/trash/quizzes/{quiz['uid']}/restore",
|
||||
headers=JSON_trash,
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert response.status_code == 200, response.text[:300]
|
||||
|
||||
refresh_snapshot()
|
||||
for table in ("quiz_questions", "quiz_options", "quiz_attempts", "quiz_answers"):
|
||||
assert get_table(table).count(quiz_uid=quiz["uid"], deleted_at=None) > 0
|
||||
assert requests.get(f"{BASE_URL}/quizzes/{slug}", headers=JSON_trash).status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user