Skip to content

Fix: send validated quiz data through websocket instead of raw data#6

Merged
papricie merged 5 commits intomainfrom
fix/quote-numeric-answers-papricie
Apr 9, 2026
Merged

Fix: send validated quiz data through websocket instead of raw data#6
papricie merged 5 commits intomainfrom
fix/quote-numeric-answers-papricie

Conversation

@papricie
Copy link
Copy Markdown
Contributor

@papricie papricie commented Apr 8, 2026

  • Changed Quiz() validation to store the result in validated_quiz variable
  • Changed send_receive_messages() to send model_dump() of validated_quiz
  • This ensures numeric answers are converted to strings before sending to server
  • Fixes issue Linux quiz YAML is not valid #2

- Changed Quiz() validation to store the result in validated_quiz variable
- Changed send_receive_messages() to send model_dump() of validated_quiz
- This ensures numeric answers are converted to strings before sending to server
- Fixes issue #2
@papricie papricie self-assigned this Apr 8, 2026
@papricie papricie added the bug Something isn't working label Apr 8, 2026
@papricie papricie linked an issue Apr 8, 2026 that may be closed by this pull request
papricie added 4 commits April 8, 2026 14:43
- Added pytest as dev dependency in pyproject.toml
- Created tests package with proper module documentation (__init__.py)
- Added TestQuizValidation class in tests/test_main.py
- Added test_numeric_answers_are_converted_to_strings() test case

Test implementation:
- Verifies that numeric answers from YAML are validated by Quiz model
- Confirms that model_dump() converts integer answers to strings
- Ensures websocket receives properly formatted data with string types

Implementation notes:
- Fixed main() function to store validated_quiz object
- Changed send_receive_messages() to send validated_quiz.model_dump()
- This change pairs with quiz-common PR #2 for full functionality

Known limitation:
- Test cannot currently run locally as quiz-common PR #2 is not yet merged
- Once both PRs are merged, test will pass: uv run pytest tests/test_main.py -v
- Setup for local testing to be documented during project sync meeting

Related to issue #2
- Changed main() to store validated quiz in validated_quiz variable
- Changed send_receive_messages() to accept validated Quiz object
- Ensures numeric answers are converted to strings before sending to server
- Removed pytest dependency from main project dependencies
- This pairs with quiz-common PR #2 for full functionality

Changes:
- src/quiz_admin/__main__.py: Updated to use validated_quiz
- pyproject.toml: Removed pytest

Note: This fix requires quiz-common PR #2 to be merged for complete integration.
Numeric answer conversion happens in quiz-common Option model via field validator.
@papricie papricie merged commit 5729d06 into main Apr 9, 2026
2 checks passed
@papricie papricie deleted the fix/quote-numeric-answers-papricie branch April 9, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux quiz YAML is not valid

2 participants