Skip to content

test(quiz): first unit coverage for the answer submission flow#86

Open
tongshu2023 wants to merge 1 commit into
zijinz456:mainfrom
tongshu2023:claude/issue-32-quiz-submission-tests
Open

test(quiz): first unit coverage for the answer submission flow#86
tongshu2023 wants to merge 1 commit into
zijinz456:mainfrom
tongshu2023:claude/issue-32-quiz-submission-tests

Conversation

@tongshu2023

Copy link
Copy Markdown

Summary

Closes #32.

submit_answer handles grading, LLM error classification, wrong-answer records, LOOM mastery updates, and background diagnostics — and had zero tests. This adds the first unit coverage, calling the endpoint function directly against a real in-memory SQLite database (auth dependency bypassed by passing the user object; the LLM-backed classifier mocked for determinism — no real API calls).

Tests

tests/test_quiz_submission.py — 9 tests:

Happy path

  • correct submission returns the proper grade with explanation, persists a correct PracticeResult, and creates no WrongAnswer record
  • grading is case- and whitespace-insensitive

Wrong answers

  • an incorrect answer triggers error classification; the category lands on both the PracticeResult and the WrongAnswer record
  • classifier failure degrades gracefully with the error_classification_failed warning while still persisting the submission
  • wrong answers schedule both background diagnostics (auto-derive + confusion detection); correct answers schedule the effective-review check

Error cases

  • unknown problem id raises NotFoundError
  • a problem in another user's course is invisible (ownership join enforced)

Mastery

  • knowledge-pointed problems update LOOM ConceptMastery through the real BKT path (not a mock): practice/correct counters increment and the mastery score becomes positive

Results

pytest tests/test_quiz_submission.py -v: 9 passed locally.

Acceptance criteria

  • At least 5 test cases covering happy path and error cases (9)
  • LLM calls are mocked (no real API calls in tests)
  • All tests pass with pytest tests/test_quiz_submission.py -v

🤖 Generated with Claude Code

…z456#32)

submit_answer handles grading, LLM error classification, wrong-answer
records, mastery updates, and background diagnostics, but had zero
tests. These call the endpoint function directly against real in-memory
SQLite (auth bypassed by passing the user; the LLM-backed classifier
mocked for determinism).

tests/test_quiz_submission.py (9 tests):
- correct submission returns the proper grade with explanation, persists
  a correct PracticeResult, and creates no WrongAnswer record
- grading is case- and whitespace-insensitive
- an incorrect answer triggers error classification: the category lands
  on both the PracticeResult and the WrongAnswer record
- classifier failure degrades gracefully with the
  error_classification_failed warning while still persisting the result
- wrong answers schedule both background diagnostics (auto-derive +
  confusion detection); correct answers schedule the effective-review
  check
- unknown problem id raises NotFoundError
- a problem in another user's course is invisible (ownership join)
- knowledge-pointed problems update LOOM ConceptMastery (real BKT path,
  not a mock): practice/correct counters and a positive mastery score

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for quiz submission grading pipeline

1 participant