webquiz 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- webquiz-1.0.0/PKG-INFO +379 -0
- webquiz-1.0.0/README.md +347 -0
- webquiz-1.0.0/pyproject.toml +56 -0
- webquiz-1.0.0/webquiz/__init__.py +6 -0
- webquiz-1.0.0/webquiz/cli.py +306 -0
- webquiz-1.0.0/webquiz/server.py +360 -0
webquiz-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: webquiz
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A modern web-based quiz and testing system built with Python and aiohttp
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: quiz,testing,aiohttp,web,assessment,education
|
|
7
|
+
Author: Oleksandr Liabakh
|
|
8
|
+
Author-email: oduvan@gmail.com
|
|
9
|
+
Requires-Python: >=3.9,<4.0
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Education
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Education :: Testing
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
23
|
+
Classifier: Topic :: Software Development :: Testing
|
|
24
|
+
Requires-Dist: PyYAML (>=6.0.2,<7.0.0)
|
|
25
|
+
Requires-Dist: aiofiles (>=24.1.0,<25.0.0)
|
|
26
|
+
Requires-Dist: aiohttp (>=3.12.13,<4.0.0)
|
|
27
|
+
Project-URL: Bug Tracker, https://github.com/oduvan/webquiz/issues
|
|
28
|
+
Project-URL: Documentation, https://github.com/oduvan/webquiz
|
|
29
|
+
Project-URL: Homepage, https://github.com/oduvan/webquiz
|
|
30
|
+
Project-URL: Repository, https://github.com/oduvan/webquiz
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# WebQuiz
|
|
34
|
+
|
|
35
|
+
A modern web-based quiz and testing system built with Python and aiohttp that allows users to take multiple-choice tests with real-time answer validation and performance tracking.
|
|
36
|
+
|
|
37
|
+
## โจ Features
|
|
38
|
+
|
|
39
|
+
- **User Management**: Unique username registration with UUID-based session tracking
|
|
40
|
+
- **Question System**: YAML-based config with automatic file generation
|
|
41
|
+
- **Real-time Validation**: Server-side answer checking and timing
|
|
42
|
+
- **Session Persistence**: Cookie-based user sessions for seamless experience
|
|
43
|
+
- **Performance Tracking**: Server-side timing for accurate response measurement
|
|
44
|
+
- **Data Export**: Automatic CSV export of user responses with configurable file paths
|
|
45
|
+
- **Responsive UI**: Clean web interface with dark/light theme support
|
|
46
|
+
- **Comprehensive Testing**: Full test suite with integration and unit tests
|
|
47
|
+
- **Flexible File Paths**: Configurable paths for config, log, CSV, and static files
|
|
48
|
+
|
|
49
|
+
## ๐ Quick Start
|
|
50
|
+
|
|
51
|
+
### Prerequisites
|
|
52
|
+
|
|
53
|
+
- Python 3.9+ (required by aiohttp)
|
|
54
|
+
- Poetry (recommended) or pip
|
|
55
|
+
- Git
|
|
56
|
+
|
|
57
|
+
### Installation with Poetry (Recommended)
|
|
58
|
+
|
|
59
|
+
1. **Clone the repository**
|
|
60
|
+
```bash
|
|
61
|
+
git clone git@github.com:oduvan/webquiz.git
|
|
62
|
+
cd webquiz
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. **Install with Poetry**
|
|
66
|
+
```bash
|
|
67
|
+
poetry install
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
3. **Run the server**
|
|
71
|
+
```bash
|
|
72
|
+
webquiz # Foreground mode
|
|
73
|
+
webquiz -d # Daemon mode
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
4. **Open your browser**
|
|
77
|
+
```
|
|
78
|
+
http://localhost:8080
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Alternative Installation with pip
|
|
82
|
+
|
|
83
|
+
1. **Clone and set up virtual environment**
|
|
84
|
+
```bash
|
|
85
|
+
git clone git@github.com:oduvan/webquiz.git
|
|
86
|
+
cd webquiz
|
|
87
|
+
python3 -m venv venv
|
|
88
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
2. **Install dependencies**
|
|
92
|
+
```bash
|
|
93
|
+
pip install -r requirements.txt
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
3. **Run the server**
|
|
97
|
+
```bash
|
|
98
|
+
python -m webquiz.cli
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
That's it! The server will automatically create sample questions if none exist.
|
|
102
|
+
|
|
103
|
+
## ๐ Project Structure
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
webquiz/
|
|
107
|
+
โโโ pyproject.toml # Poetry configuration and dependencies
|
|
108
|
+
โโโ requirements.txt # Legacy pip dependencies
|
|
109
|
+
โโโ .gitignore # Git ignore rules
|
|
110
|
+
โโโ CLAUDE.md # Project documentation
|
|
111
|
+
โโโ README.md # This file
|
|
112
|
+
โโโ webquiz/ # Main package
|
|
113
|
+
โ โโโ __init__.py # Package initialization
|
|
114
|
+
โ โโโ cli.py # CLI entry point (webquiz command)
|
|
115
|
+
โ โโโ server.py # Main application server
|
|
116
|
+
โโโ static/ # Frontend files
|
|
117
|
+
โ โโโ index.html # Single-page web application
|
|
118
|
+
โโโ tests/ # Test suite
|
|
119
|
+
โ โโโ conftest.py # Test configuration
|
|
120
|
+
โ โโโ test_integration.py # Integration tests (11 tests)
|
|
121
|
+
โ โโโ test_server.py # Unit tests (3 tests)
|
|
122
|
+
โโโ venv/ # Virtual environment (excluded from git)
|
|
123
|
+
|
|
124
|
+
# Generated at runtime (excluded from git):
|
|
125
|
+
โโโ config.yaml # Configuration and question database
|
|
126
|
+
โโโ user_responses.csv # User response data
|
|
127
|
+
โโโ server.log # Server logs
|
|
128
|
+
โโโ webquiz.pid # Daemon process ID
|
|
129
|
+
โโโ static/questions_for_client.json # Client-safe questions
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## ๐ง API Reference
|
|
133
|
+
|
|
134
|
+
### Authentication
|
|
135
|
+
- User sessions managed via UUID stored in browser cookies
|
|
136
|
+
- No passwords required - username-based registration
|
|
137
|
+
|
|
138
|
+
### Endpoints
|
|
139
|
+
|
|
140
|
+
#### `POST /api/register`
|
|
141
|
+
Register a new user with unique username.
|
|
142
|
+
|
|
143
|
+
**Request:**
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"username": "john_doe"
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Response:**
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"username": "john_doe",
|
|
154
|
+
"user_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
155
|
+
"message": "User registered successfully"
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### `POST /api/submit-answer`
|
|
160
|
+
Submit an answer for a question.
|
|
161
|
+
|
|
162
|
+
**Request:**
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"user_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
166
|
+
"question_id": 1,
|
|
167
|
+
"selected_answer": 2
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Response:**
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"is_correct": true,
|
|
175
|
+
"time_taken": 5.23,
|
|
176
|
+
"message": "Answer submitted successfully"
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### `GET /api/verify-user/{user_id}`
|
|
181
|
+
Verify user session and get progress information.
|
|
182
|
+
|
|
183
|
+
**Response:**
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
186
|
+
"valid": true,
|
|
187
|
+
"user_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
188
|
+
"username": "john_doe",
|
|
189
|
+
"next_question_index": 2,
|
|
190
|
+
"total_questions": 5,
|
|
191
|
+
"last_answered_question_id": 1
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## ๐ฅ๏ธ CLI Commands
|
|
196
|
+
|
|
197
|
+
The `webquiz` command provides several options:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# Start server in foreground (default)
|
|
201
|
+
webquiz
|
|
202
|
+
|
|
203
|
+
# Start server with custom files
|
|
204
|
+
webquiz --config my-config.yaml
|
|
205
|
+
webquiz --log-file /var/log/webquiz.log
|
|
206
|
+
webquiz --csv-file /data/responses.csv
|
|
207
|
+
webquiz --static /var/www/quiz
|
|
208
|
+
|
|
209
|
+
# Combine multiple custom paths
|
|
210
|
+
webquiz --config quiz.yaml --log-file quiz.log --csv-file quiz.csv --static web/
|
|
211
|
+
|
|
212
|
+
# Start server as daemon (background)
|
|
213
|
+
webquiz -d
|
|
214
|
+
webquiz --daemon
|
|
215
|
+
|
|
216
|
+
# Stop daemon server
|
|
217
|
+
webquiz --stop
|
|
218
|
+
|
|
219
|
+
# Check daemon status
|
|
220
|
+
webquiz --status
|
|
221
|
+
|
|
222
|
+
# Show help
|
|
223
|
+
webquiz --help
|
|
224
|
+
|
|
225
|
+
# Show version
|
|
226
|
+
webquiz --version
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Daemon Mode Features
|
|
230
|
+
|
|
231
|
+
- **Background execution**: Server runs independently in background
|
|
232
|
+
- **PID file management**: Automatic process tracking via `webquiz.pid`
|
|
233
|
+
- **Graceful shutdown**: Proper cleanup on stop
|
|
234
|
+
- **Status monitoring**: Check if daemon is running
|
|
235
|
+
- **Log preservation**: All output still goes to `server.log`
|
|
236
|
+
|
|
237
|
+
## ๐งช Testing
|
|
238
|
+
|
|
239
|
+
Run the comprehensive test suite:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# With Poetry
|
|
243
|
+
poetry run pytest
|
|
244
|
+
|
|
245
|
+
# Or directly
|
|
246
|
+
pytest tests/
|
|
247
|
+
|
|
248
|
+
# Run with verbose output
|
|
249
|
+
pytest tests/ -v
|
|
250
|
+
|
|
251
|
+
# Run only integration tests
|
|
252
|
+
pytest tests/test_integration.py
|
|
253
|
+
|
|
254
|
+
# Run only unit tests
|
|
255
|
+
pytest tests/test_server.py
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Test Coverage
|
|
259
|
+
- **11 Integration Tests**: End-to-end API testing with real HTTP requests
|
|
260
|
+
- **3 Unit Tests**: Internal functionality testing (CSV, YAML, data structures)
|
|
261
|
+
- **Total**: 14 tests covering all critical functionality
|
|
262
|
+
|
|
263
|
+
## ๐ Configuration Format
|
|
264
|
+
|
|
265
|
+
Questions are stored in `config.yaml` (auto-generated if missing):
|
|
266
|
+
|
|
267
|
+
```yaml
|
|
268
|
+
questions:
|
|
269
|
+
- id: 1
|
|
270
|
+
question: "What is 2 + 2?"
|
|
271
|
+
options:
|
|
272
|
+
- "3"
|
|
273
|
+
- "4"
|
|
274
|
+
- "5"
|
|
275
|
+
- "6"
|
|
276
|
+
correct_answer: 1 # 0-indexed (option "4")
|
|
277
|
+
|
|
278
|
+
- id: 2
|
|
279
|
+
question: "What is the capital of France?"
|
|
280
|
+
options:
|
|
281
|
+
- "London"
|
|
282
|
+
- "Berlin"
|
|
283
|
+
- "Paris"
|
|
284
|
+
- "Madrid"
|
|
285
|
+
correct_answer: 2 # 0-indexed (option "Paris")
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## ๐ Data Export
|
|
289
|
+
|
|
290
|
+
User responses are automatically exported to `user_responses.csv`:
|
|
291
|
+
|
|
292
|
+
```csv
|
|
293
|
+
user_id,username,question_text,selected_answer_text,correct_answer_text,is_correct,time_taken_seconds
|
|
294
|
+
550e8400-e29b-41d4-a716-446655440000,john_doe,"What is 2 + 2?","4","4",True,3.45
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## ๐จ Customization
|
|
298
|
+
|
|
299
|
+
### Adding Your Own Questions
|
|
300
|
+
|
|
301
|
+
1. **Edit config.yaml** (created automatically on first run)
|
|
302
|
+
2. **Restart the server** to load new questions
|
|
303
|
+
3. **Questions must have unique IDs** and 0-indexed correct answers
|
|
304
|
+
4. **Use custom file paths**:
|
|
305
|
+
- Config: `webquiz --config my-questions.yaml`
|
|
306
|
+
- Logs: `webquiz --log-file /var/log/quiz.log`
|
|
307
|
+
- CSV: `webquiz --csv-file /data/responses.csv`
|
|
308
|
+
- Static files: `webquiz --static /var/www/quiz`
|
|
309
|
+
|
|
310
|
+
### Styling
|
|
311
|
+
|
|
312
|
+
- Modify `static/index.html` for UI changes
|
|
313
|
+
- Built-in dark/light theme toggle
|
|
314
|
+
- Responsive design works on mobile and desktop
|
|
315
|
+
|
|
316
|
+
## ๐ ๏ธ Development
|
|
317
|
+
|
|
318
|
+
### Key Technical Decisions
|
|
319
|
+
|
|
320
|
+
- **Server-side timing**: All timing calculated server-side for accuracy
|
|
321
|
+
- **UUID-based sessions**: Secure user identification without passwords
|
|
322
|
+
- **Middleware error handling**: Clean error management with proper HTTP status codes
|
|
323
|
+
- **CSV module usage**: Proper escaping for data with commas/quotes
|
|
324
|
+
- **Auto-file generation**: Zero-configuration setup with sensible defaults
|
|
325
|
+
|
|
326
|
+
### Architecture
|
|
327
|
+
|
|
328
|
+
- **Backend**: Python 3.9+ with aiohttp async web framework
|
|
329
|
+
- **Frontend**: Vanilla HTML/CSS/JavaScript (no frameworks)
|
|
330
|
+
- **Storage**: In-memory with periodic CSV backups (30-second intervals)
|
|
331
|
+
- **Session Management**: Cookie-based with server-side validation
|
|
332
|
+
|
|
333
|
+
## ๐ Troubleshooting
|
|
334
|
+
|
|
335
|
+
### Common Issues
|
|
336
|
+
|
|
337
|
+
**Port already in use:**
|
|
338
|
+
```bash
|
|
339
|
+
# Kill process using port 8080
|
|
340
|
+
lsof -ti:8080 | xargs kill -9
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**Virtual environment issues:**
|
|
344
|
+
```bash
|
|
345
|
+
# Recreate virtual environment
|
|
346
|
+
rm -rf venv
|
|
347
|
+
python3 -m venv venv
|
|
348
|
+
source venv/bin/activate
|
|
349
|
+
pip install -r requirements.txt
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**Questions not loading:**
|
|
353
|
+
- Check that `config.yaml` has valid YAML syntax
|
|
354
|
+
- Restart server after editing config file
|
|
355
|
+
- Check server logs for errors
|
|
356
|
+
- Use custom file paths:
|
|
357
|
+
- `--config` for custom config file
|
|
358
|
+
- `--log-file` for custom log location
|
|
359
|
+
- `--csv-file` for custom CSV output location
|
|
360
|
+
- `--static` for custom static files directory
|
|
361
|
+
|
|
362
|
+
## ๐ License
|
|
363
|
+
|
|
364
|
+
This project is open source. Feel free to use and modify as needed.
|
|
365
|
+
|
|
366
|
+
## ๐ค Contributing
|
|
367
|
+
|
|
368
|
+
1. Fork the repository
|
|
369
|
+
2. Create a feature branch
|
|
370
|
+
3. Add tests for new functionality
|
|
371
|
+
4. Ensure all tests pass
|
|
372
|
+
5. Submit a pull request
|
|
373
|
+
|
|
374
|
+
## ๐ Support
|
|
375
|
+
|
|
376
|
+
For questions or issues:
|
|
377
|
+
- Check the server logs (`server.log`)
|
|
378
|
+
- Run the test suite to verify setup
|
|
379
|
+
- Review this README and `CLAUDE.md` for detailed documentation
|
webquiz-1.0.0/README.md
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
# WebQuiz
|
|
2
|
+
|
|
3
|
+
A modern web-based quiz and testing system built with Python and aiohttp that allows users to take multiple-choice tests with real-time answer validation and performance tracking.
|
|
4
|
+
|
|
5
|
+
## โจ Features
|
|
6
|
+
|
|
7
|
+
- **User Management**: Unique username registration with UUID-based session tracking
|
|
8
|
+
- **Question System**: YAML-based config with automatic file generation
|
|
9
|
+
- **Real-time Validation**: Server-side answer checking and timing
|
|
10
|
+
- **Session Persistence**: Cookie-based user sessions for seamless experience
|
|
11
|
+
- **Performance Tracking**: Server-side timing for accurate response measurement
|
|
12
|
+
- **Data Export**: Automatic CSV export of user responses with configurable file paths
|
|
13
|
+
- **Responsive UI**: Clean web interface with dark/light theme support
|
|
14
|
+
- **Comprehensive Testing**: Full test suite with integration and unit tests
|
|
15
|
+
- **Flexible File Paths**: Configurable paths for config, log, CSV, and static files
|
|
16
|
+
|
|
17
|
+
## ๐ Quick Start
|
|
18
|
+
|
|
19
|
+
### Prerequisites
|
|
20
|
+
|
|
21
|
+
- Python 3.9+ (required by aiohttp)
|
|
22
|
+
- Poetry (recommended) or pip
|
|
23
|
+
- Git
|
|
24
|
+
|
|
25
|
+
### Installation with Poetry (Recommended)
|
|
26
|
+
|
|
27
|
+
1. **Clone the repository**
|
|
28
|
+
```bash
|
|
29
|
+
git clone git@github.com:oduvan/webquiz.git
|
|
30
|
+
cd webquiz
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
2. **Install with Poetry**
|
|
34
|
+
```bash
|
|
35
|
+
poetry install
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
3. **Run the server**
|
|
39
|
+
```bash
|
|
40
|
+
webquiz # Foreground mode
|
|
41
|
+
webquiz -d # Daemon mode
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
4. **Open your browser**
|
|
45
|
+
```
|
|
46
|
+
http://localhost:8080
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Alternative Installation with pip
|
|
50
|
+
|
|
51
|
+
1. **Clone and set up virtual environment**
|
|
52
|
+
```bash
|
|
53
|
+
git clone git@github.com:oduvan/webquiz.git
|
|
54
|
+
cd webquiz
|
|
55
|
+
python3 -m venv venv
|
|
56
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
2. **Install dependencies**
|
|
60
|
+
```bash
|
|
61
|
+
pip install -r requirements.txt
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
3. **Run the server**
|
|
65
|
+
```bash
|
|
66
|
+
python -m webquiz.cli
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
That's it! The server will automatically create sample questions if none exist.
|
|
70
|
+
|
|
71
|
+
## ๐ Project Structure
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
webquiz/
|
|
75
|
+
โโโ pyproject.toml # Poetry configuration and dependencies
|
|
76
|
+
โโโ requirements.txt # Legacy pip dependencies
|
|
77
|
+
โโโ .gitignore # Git ignore rules
|
|
78
|
+
โโโ CLAUDE.md # Project documentation
|
|
79
|
+
โโโ README.md # This file
|
|
80
|
+
โโโ webquiz/ # Main package
|
|
81
|
+
โ โโโ __init__.py # Package initialization
|
|
82
|
+
โ โโโ cli.py # CLI entry point (webquiz command)
|
|
83
|
+
โ โโโ server.py # Main application server
|
|
84
|
+
โโโ static/ # Frontend files
|
|
85
|
+
โ โโโ index.html # Single-page web application
|
|
86
|
+
โโโ tests/ # Test suite
|
|
87
|
+
โ โโโ conftest.py # Test configuration
|
|
88
|
+
โ โโโ test_integration.py # Integration tests (11 tests)
|
|
89
|
+
โ โโโ test_server.py # Unit tests (3 tests)
|
|
90
|
+
โโโ venv/ # Virtual environment (excluded from git)
|
|
91
|
+
|
|
92
|
+
# Generated at runtime (excluded from git):
|
|
93
|
+
โโโ config.yaml # Configuration and question database
|
|
94
|
+
โโโ user_responses.csv # User response data
|
|
95
|
+
โโโ server.log # Server logs
|
|
96
|
+
โโโ webquiz.pid # Daemon process ID
|
|
97
|
+
โโโ static/questions_for_client.json # Client-safe questions
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## ๐ง API Reference
|
|
101
|
+
|
|
102
|
+
### Authentication
|
|
103
|
+
- User sessions managed via UUID stored in browser cookies
|
|
104
|
+
- No passwords required - username-based registration
|
|
105
|
+
|
|
106
|
+
### Endpoints
|
|
107
|
+
|
|
108
|
+
#### `POST /api/register`
|
|
109
|
+
Register a new user with unique username.
|
|
110
|
+
|
|
111
|
+
**Request:**
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"username": "john_doe"
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Response:**
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"username": "john_doe",
|
|
122
|
+
"user_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
123
|
+
"message": "User registered successfully"
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### `POST /api/submit-answer`
|
|
128
|
+
Submit an answer for a question.
|
|
129
|
+
|
|
130
|
+
**Request:**
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"user_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
134
|
+
"question_id": 1,
|
|
135
|
+
"selected_answer": 2
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Response:**
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"is_correct": true,
|
|
143
|
+
"time_taken": 5.23,
|
|
144
|
+
"message": "Answer submitted successfully"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### `GET /api/verify-user/{user_id}`
|
|
149
|
+
Verify user session and get progress information.
|
|
150
|
+
|
|
151
|
+
**Response:**
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"valid": true,
|
|
155
|
+
"user_id": "550e8400-e29b-41d4-a716-446655440000",
|
|
156
|
+
"username": "john_doe",
|
|
157
|
+
"next_question_index": 2,
|
|
158
|
+
"total_questions": 5,
|
|
159
|
+
"last_answered_question_id": 1
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## ๐ฅ๏ธ CLI Commands
|
|
164
|
+
|
|
165
|
+
The `webquiz` command provides several options:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Start server in foreground (default)
|
|
169
|
+
webquiz
|
|
170
|
+
|
|
171
|
+
# Start server with custom files
|
|
172
|
+
webquiz --config my-config.yaml
|
|
173
|
+
webquiz --log-file /var/log/webquiz.log
|
|
174
|
+
webquiz --csv-file /data/responses.csv
|
|
175
|
+
webquiz --static /var/www/quiz
|
|
176
|
+
|
|
177
|
+
# Combine multiple custom paths
|
|
178
|
+
webquiz --config quiz.yaml --log-file quiz.log --csv-file quiz.csv --static web/
|
|
179
|
+
|
|
180
|
+
# Start server as daemon (background)
|
|
181
|
+
webquiz -d
|
|
182
|
+
webquiz --daemon
|
|
183
|
+
|
|
184
|
+
# Stop daemon server
|
|
185
|
+
webquiz --stop
|
|
186
|
+
|
|
187
|
+
# Check daemon status
|
|
188
|
+
webquiz --status
|
|
189
|
+
|
|
190
|
+
# Show help
|
|
191
|
+
webquiz --help
|
|
192
|
+
|
|
193
|
+
# Show version
|
|
194
|
+
webquiz --version
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Daemon Mode Features
|
|
198
|
+
|
|
199
|
+
- **Background execution**: Server runs independently in background
|
|
200
|
+
- **PID file management**: Automatic process tracking via `webquiz.pid`
|
|
201
|
+
- **Graceful shutdown**: Proper cleanup on stop
|
|
202
|
+
- **Status monitoring**: Check if daemon is running
|
|
203
|
+
- **Log preservation**: All output still goes to `server.log`
|
|
204
|
+
|
|
205
|
+
## ๐งช Testing
|
|
206
|
+
|
|
207
|
+
Run the comprehensive test suite:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# With Poetry
|
|
211
|
+
poetry run pytest
|
|
212
|
+
|
|
213
|
+
# Or directly
|
|
214
|
+
pytest tests/
|
|
215
|
+
|
|
216
|
+
# Run with verbose output
|
|
217
|
+
pytest tests/ -v
|
|
218
|
+
|
|
219
|
+
# Run only integration tests
|
|
220
|
+
pytest tests/test_integration.py
|
|
221
|
+
|
|
222
|
+
# Run only unit tests
|
|
223
|
+
pytest tests/test_server.py
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Test Coverage
|
|
227
|
+
- **11 Integration Tests**: End-to-end API testing with real HTTP requests
|
|
228
|
+
- **3 Unit Tests**: Internal functionality testing (CSV, YAML, data structures)
|
|
229
|
+
- **Total**: 14 tests covering all critical functionality
|
|
230
|
+
|
|
231
|
+
## ๐ Configuration Format
|
|
232
|
+
|
|
233
|
+
Questions are stored in `config.yaml` (auto-generated if missing):
|
|
234
|
+
|
|
235
|
+
```yaml
|
|
236
|
+
questions:
|
|
237
|
+
- id: 1
|
|
238
|
+
question: "What is 2 + 2?"
|
|
239
|
+
options:
|
|
240
|
+
- "3"
|
|
241
|
+
- "4"
|
|
242
|
+
- "5"
|
|
243
|
+
- "6"
|
|
244
|
+
correct_answer: 1 # 0-indexed (option "4")
|
|
245
|
+
|
|
246
|
+
- id: 2
|
|
247
|
+
question: "What is the capital of France?"
|
|
248
|
+
options:
|
|
249
|
+
- "London"
|
|
250
|
+
- "Berlin"
|
|
251
|
+
- "Paris"
|
|
252
|
+
- "Madrid"
|
|
253
|
+
correct_answer: 2 # 0-indexed (option "Paris")
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## ๐ Data Export
|
|
257
|
+
|
|
258
|
+
User responses are automatically exported to `user_responses.csv`:
|
|
259
|
+
|
|
260
|
+
```csv
|
|
261
|
+
user_id,username,question_text,selected_answer_text,correct_answer_text,is_correct,time_taken_seconds
|
|
262
|
+
550e8400-e29b-41d4-a716-446655440000,john_doe,"What is 2 + 2?","4","4",True,3.45
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## ๐จ Customization
|
|
266
|
+
|
|
267
|
+
### Adding Your Own Questions
|
|
268
|
+
|
|
269
|
+
1. **Edit config.yaml** (created automatically on first run)
|
|
270
|
+
2. **Restart the server** to load new questions
|
|
271
|
+
3. **Questions must have unique IDs** and 0-indexed correct answers
|
|
272
|
+
4. **Use custom file paths**:
|
|
273
|
+
- Config: `webquiz --config my-questions.yaml`
|
|
274
|
+
- Logs: `webquiz --log-file /var/log/quiz.log`
|
|
275
|
+
- CSV: `webquiz --csv-file /data/responses.csv`
|
|
276
|
+
- Static files: `webquiz --static /var/www/quiz`
|
|
277
|
+
|
|
278
|
+
### Styling
|
|
279
|
+
|
|
280
|
+
- Modify `static/index.html` for UI changes
|
|
281
|
+
- Built-in dark/light theme toggle
|
|
282
|
+
- Responsive design works on mobile and desktop
|
|
283
|
+
|
|
284
|
+
## ๐ ๏ธ Development
|
|
285
|
+
|
|
286
|
+
### Key Technical Decisions
|
|
287
|
+
|
|
288
|
+
- **Server-side timing**: All timing calculated server-side for accuracy
|
|
289
|
+
- **UUID-based sessions**: Secure user identification without passwords
|
|
290
|
+
- **Middleware error handling**: Clean error management with proper HTTP status codes
|
|
291
|
+
- **CSV module usage**: Proper escaping for data with commas/quotes
|
|
292
|
+
- **Auto-file generation**: Zero-configuration setup with sensible defaults
|
|
293
|
+
|
|
294
|
+
### Architecture
|
|
295
|
+
|
|
296
|
+
- **Backend**: Python 3.9+ with aiohttp async web framework
|
|
297
|
+
- **Frontend**: Vanilla HTML/CSS/JavaScript (no frameworks)
|
|
298
|
+
- **Storage**: In-memory with periodic CSV backups (30-second intervals)
|
|
299
|
+
- **Session Management**: Cookie-based with server-side validation
|
|
300
|
+
|
|
301
|
+
## ๐ Troubleshooting
|
|
302
|
+
|
|
303
|
+
### Common Issues
|
|
304
|
+
|
|
305
|
+
**Port already in use:**
|
|
306
|
+
```bash
|
|
307
|
+
# Kill process using port 8080
|
|
308
|
+
lsof -ti:8080 | xargs kill -9
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Virtual environment issues:**
|
|
312
|
+
```bash
|
|
313
|
+
# Recreate virtual environment
|
|
314
|
+
rm -rf venv
|
|
315
|
+
python3 -m venv venv
|
|
316
|
+
source venv/bin/activate
|
|
317
|
+
pip install -r requirements.txt
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Questions not loading:**
|
|
321
|
+
- Check that `config.yaml` has valid YAML syntax
|
|
322
|
+
- Restart server after editing config file
|
|
323
|
+
- Check server logs for errors
|
|
324
|
+
- Use custom file paths:
|
|
325
|
+
- `--config` for custom config file
|
|
326
|
+
- `--log-file` for custom log location
|
|
327
|
+
- `--csv-file` for custom CSV output location
|
|
328
|
+
- `--static` for custom static files directory
|
|
329
|
+
|
|
330
|
+
## ๐ License
|
|
331
|
+
|
|
332
|
+
This project is open source. Feel free to use and modify as needed.
|
|
333
|
+
|
|
334
|
+
## ๐ค Contributing
|
|
335
|
+
|
|
336
|
+
1. Fork the repository
|
|
337
|
+
2. Create a feature branch
|
|
338
|
+
3. Add tests for new functionality
|
|
339
|
+
4. Ensure all tests pass
|
|
340
|
+
5. Submit a pull request
|
|
341
|
+
|
|
342
|
+
## ๐ Support
|
|
343
|
+
|
|
344
|
+
For questions or issues:
|
|
345
|
+
- Check the server logs (`server.log`)
|
|
346
|
+
- Run the test suite to verify setup
|
|
347
|
+
- Review this README and `CLAUDE.md` for detailed documentation
|