WebQuiz
A modern web-based quiz and testing system built with Python and aiohttp that allows users to take multiple-choice and text input tests with real-time answer validation and performance tracking.
✨ Features
- Multi-Quiz System: Questions loaded from
quizzes/ directory with multiple YAML files
- Multiple Question Types: Single choice, multiple choice, and text input questions with Python-based validation
- Admin Interface: Web-based admin panel with master key authentication for quiz management
- Registration Approval: Optional admin approval workflow for new registrations with real-time notifications
- Question Randomization: Configurable per-student question order randomization for fair testing
- Question Grouping: Keep related questions together during randomization with
stick_to_the_previous attribute
- Question Explanations: Optional Markdown explanation (with images) shown as its own step after each answer, written in the quiz editor with a preview
- Dynamic Answer Visibility: Optional delayed answer reveal - show correct answers only after all students complete
- Manual Answer Control: Admin button to reveal answers immediately without waiting for all students
- Dynamic Quiz Switching: Real-time quiz switching with automatic server state reset
- Config File Editor: Web-based configuration editor with Form and YAML views, real-time validation
- Live Statistics: Real-time WebSocket-powered dashboard showing user progress
- Real-time Validation: Server-side answer checking with immediate feedback
- Session Persistence: Cookie-based user sessions for seamless experience
- Connection Retry: The quiz page repeats requests when the connection drops; answers and registrations are never counted twice
- Performance Tracking: Server-side timing for accurate response measurement
- Data Export: Automatic CSV export with quiz-prefixed filenames and unique suffixes
- AI Integration: Use ChatGPT/Claude for analyzing quiz results and generating questions from existing materials
- Responsive UI: Clean web interface with dark/light theme support
- SSH Tunnel Support: Optional public access via SSH reverse tunnel with auto-reconnect
- Binary Distribution: Standalone PyInstaller executable with auto-configuration
- Comprehensive Testing: 222+ tests covering all functionality with CI/CD pipeline
- Flexible File Paths: Configurable paths for quizzes, logs, CSV, and static files
🚀 Quick Start
Prerequisites
- Python 3.10-3.14 (required by aiohttp)
- Poetry (recommended) or pip
- Git
Installation with Poetry (Recommended)
-
Clone the repository
git clone git@github.com:oduvan/webquiz.git
cd webquiz
-
Install with Poetry
poetry install
-
Run the server
webquiz # Foreground mode
webquiz -d # Daemon mode
-
Open your browser
http://localhost:8080
The server will automatically create necessary directories and files on first run.
Alternative Installation with pip
-
Clone and set up virtual environment
git clone git@github.com:oduvan/webquiz.git
cd webquiz
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run the server
python -m webquiz.cli
The server will automatically create necessary directories and files on first run.
📁 Project Structure
webquiz/
├── pyproject.toml # Poetry configuration and dependencies
├── requirements.txt # Legacy pip dependencies
├── .gitignore # Git ignore rules
├── CLAUDE.md # Project documentation
├── README.md # This file
├── webquiz/ # Main package
│ ├── __init__.py # Package initialization
│ ├── cli.py # CLI entry point (webquiz command)
│ ├── server.py # Main application server
│ ├── build.py # PyInstaller binary build script
│ ├── binary_entry.py # Binary executable entry point
│ ├── version_check.py # Version update checking
│ ├── server_config.yaml.example # Configuration example
│ └── templates/ # HTML templates
│ ├── index.html # Main quiz interface
│ ├── admin.html # Admin management panel
│ ├── files.html # File manager interface
│ ├── live_stats.html # Live statistics dashboard
│ ├── quiz_selection_required.html # Quiz selection prompt
│ └── template_error.html # Error page template
├── tests/ # Test suite (14 test files)
│ ├── conftest.py # Test fixtures and configuration
│ ├── test_cli_directory_creation.py # CLI and directory tests
│ ├── test_admin_api.py # Admin API tests
│ ├── test_admin_quiz_management.py # Quiz management tests
│ ├── test_config_management.py # Config editor tests
│ ├── test_registration_approval.py # Registration approval tests
│ ├── test_registration_fields.py # Registration fields tests
│ ├── test_index_generation.py # Template generation tests
│ ├── test_files_management.py # File manager tests
│ ├── test_integration_multiple_choice.py # Multiple choice integration tests
│ ├── test_multiple_answers.py # Multiple answer tests
│ ├── test_show_right_answer.py # Show answer tests
│ ├── test_selenium_multiple_choice.py # Selenium multiple choice tests
│ ├── test_selenium_registration_fields.py # Selenium registration tests
│ └── test_user_journey_selenium.py # Selenium user journey tests
└── .github/
└── workflows/
└── test.yml # CI/CD pipeline
# Generated at runtime (excluded from git):
└── quizzes/ # Quiz files directory
├── default.yaml # Default quiz (auto-created)
└── *.yaml # Additional quiz files
🖥️ CLI Commands
The webquiz command provides several options:
# Start server in foreground (default)
webquiz
# Start server with admin interface (requires master key)
webquiz --master-key secret123
# Start server on a custom port
webquiz --port 9090
# Start server with custom directories
webquiz --quizzes-dir my_quizzes
webquiz --logs-dir /var/log
webquiz --csv-dir /data
webquiz --static /var/www/quiz
# Combine multiple options
webquiz --master-key secret123 --quizzes-dir quizzes --logs-dir logs
# Set master key via environment variable
export WEBQUIZ_MASTER_KEY=secret123
webquiz
# Start server as daemon (background)
webquiz -d
webquiz --daemon
# Stop daemon server
webquiz --stop
# Check daemon status
webquiz --status
# Show help
webquiz --help
# Show version
webquiz --version
Key Options
--master-key: Enable admin interface with authentication
--port: Port to listen on (default: 8080)
--quizzes-dir: Directory containing quiz YAML files (default: ./quizzes)
--logs-dir: Directory for server logs (default: current directory)
--csv-dir: Directory for CSV exports (default: current directory)
--static: Directory for static files (default: ./static)
-d, --daemon: Run server in background
--stop: Stop daemon server
--status: Check daemon status
Daemon Mode Features
- Background execution: Server runs independently in background
- PID file management: Automatic process tracking via
webquiz.pid
- Graceful shutdown: Proper cleanup on stop
- Status monitoring: Check if daemon is running
- Log preservation: All output still goes to
server.log
🚀 Release Management
This project uses GitHub Actions for automated versioning, PyPI deployment, and GitHub Release creation.
Creating a New Release
- Go to GitHub Actions in the repository
- Select "Release and Deploy to PyPI" workflow
- Click "Run workflow"
- Enter the new version (e.g.,
1.0.6, 2.0.0)
- Click "Run workflow"
The action will automatically:
- ✅ Update version in
pyproject.toml and webquiz/__init__.py
- ✅ Run tests to ensure everything works
- ✅ Commit the version changes
- ✅ Create a git tag with the version
- ✅ Build the package using Poetry
- ✅ Publish to PyPI
- 🆕 Create a GitHub Release with built artifacts
What's included in GitHub Releases
Each release automatically includes:
- 📦 Python wheel package (
.whl file)
- 📋 Source distribution (
.tar.gz file)
- 📝 Formatted release notes with installation instructions
- 🔗 Links to commit history for detailed changelog
- 📋 Installation commands for the specific version
Prerequisites for Release Deployment
Repository maintainers need to set up:
PYPI_API_TOKEN secret in GitHub repository settings
- PyPI account with publish permissions for the
webquiz package
GITHUB_TOKEN is automatically provided by GitHub Actions
🧪 Testing
Run the comprehensive test suite:
# With Poetry
poetry run pytest
# Or directly
pytest tests/
# Run with verbose output
pytest tests/ -v
# Run in parallel with 4 workers
pytest tests/ -v -n 4
# Run specific test file
pytest tests/test_admin_api.py
pytest tests/test_registration_approval.py
Test Coverage
The project has 958 tests across 75 test files. The main areas:
- CLI and Directory Creation (7 tests): Directory and file creation
- Admin API (14 tests): Admin interface and authentication
- Admin Quiz Management (18 tests): Quiz switching and management
- Admin Quiz Editor (7 tests): Wizard mode quiz creation with randomize_questions and show_answers_on_completion
- Config Management (23 tests): Config editor, validation, and form-based JSON updates
- Registration Approval (20 tests): Approval workflow and timing
- Files Management (38 tests): File manager interface
- CSV Table Viewer (17 tests): Table page with question/user filters, pop-up and new window (
test_csv_table_viewer.py, test_selenium_csv_table_viewer.py)
- SSH Tunnel (31 tests): Key generation, config fetch, connect/disconnect (
test_tunnel.py)
- File Transfer (61 tests): Sending files between servers through the tunnel (
test_transfer.py, test_transfer_api.py)
- Network Access (22 tests): Local network restriction and proxy header handling
- Private Quiz Archives (6 tests): Downloading quizzes from token-protected archives (
test_download_quiz_token.py)
- Index Generation (18 tests): Template generation tests
- Registration Fields (12 tests): Custom registration fields
- Show Right Answer (5 tests): Answer display functionality
- Show Answers on Completion (10 tests): Dynamic answer visibility after all students complete
- Time Limits (57 tests): Per-question and whole-quiz time limits, timeouts, background check, countdowns, editor fields (
test_time_limits_*.py, test_selenium_time_limits.py, test_selenium_admin_time_limits.py)
- Start Settings (11 tests): Settings pop-up when starting a quiz; values apply to the running quiz only (
test_quiz_start_settings.py, test_selenium_admin_start_settings.py)
- Question Explanations (53 tests): Markdown rendering, the answer reply, the explanation step, editor field and preview, start pop-up (
test_explanations*.py, test_selenium_explanations.py, test_selenium_admin_explanations.py)
- Manual Check (47 tests): Answers the teacher checks by hand, review queue shared by several teachers, review page, results that update by themselves, CSV rewrite (
test_manual_check.py, test_manual_review_unit.py, test_selenium_manual_check.py)
- Hidden Correctness (2 tests): The results table leaves out the "correct" column while correct answers are hidden (
test_selenium_hidden_correctness.py)
- Harness Checks (14 tests): The classroom harness's data and agent-report checks, on small fake records (
test_harness_checks.py)
- Integration Tests (6 tests): Multiple choice, multiple answers
- Selenium Tests (96 tests): End-to-end browser testing
- Auto-Advance (6 tests): Automatic progression behavior
The test suite uses GitHub Actions CI/CD for automated testing on every commit.
Classroom Test Harness
harness/ runs a real WebQuiz server and lets a whole class take a quiz in real browsers: a scripted teacher starts the quiz, scripted students act at exact times (answers at the time limit, Wi-Fi drops, reloads), and AI agent students take the quiz and report what they did and saw. The harness then checks that the agents' reports, the browser record and the stored CSV data all agree. It is not part of the normal test run. See harness/README.md.
pip install -r harness/requirements.txt
python -m harness.run time-edges --no-agents # scripted students only
🔥 Stress Testing
Stress testing has been moved to a separate project for better maintainability and independent versioning.
Installation
# Install from PyPI
pip install webquiz-stress-test
# Or download pre-built binaries from releases
# https://github.com/oduvan/webquiz-stress-test/releases
Quick Start
# Basic test with 10 concurrent users
webquiz-stress-test
# Heavy load test with 100 users
webquiz-stress-test -c 100
# Test custom server
webquiz-stress-test -u http://localhost:9000 -c 50
Features
- Concurrent client simulation with configurable users
- Realistic user behavior (random delays, page reloads)
- Randomized quiz support
- Approval workflow testing
- Detailed performance statistics
- Multi-platform binaries (Linux, macOS, Windows)
Documentation
For complete documentation, see the webquiz-stress-test repository.
📋 Configuration Format
Quiz Files
Questions are stored in YAML files in the quizzes/ directory. The server automatically creates a default.yaml file if the directory is empty.
Example quiz file (quizzes/math_quiz.yaml):
title: "Mathematics Quiz"
randomize_questions: true # Set to true to randomize question order for each student (default: false)
questions:
- question: "What is 2 + 2?"
options:
- "3"
- "4"
- "5"
- "6"
correct_answer: 1 # 0-indexed (option "4")
- question: "What is 5 × 3?"
options:
- "10"
- "15"
- "20"
- "25"
correct_answer: 1 # 0-indexed (option "15")
Question Randomization:
- Set
randomize_questions: true in your quiz YAML to give each student a unique question order
- Each student receives a randomized order that persists across sessions
- Helps prevent cheating and ensures fair testing
- Default is
false (questions appear in YAML order)
Copy Protection:
- Question text and answer options cannot be selected or copied by students
- Prevents sharing quiz content via copy-paste
Question Grouping (stick_to_the_previous):
- Use
stick_to_the_previous: true on questions that should stay adjacent to their predecessor during randomization
- Useful for reading passages followed by related questions
- Groups are shuffled as units while preserving internal order
- Example: Q1→Q2(sticky)→Q3(sticky) always appear together as [Q1,Q2,Q3]
- First question cannot have this flag (no previous question)
- Admin panel shows 🔗 indicator on grouped questions
Question Points: