ClassOS testing is organized into three layers:
- Unit tests β Individual module logic
- Integration tests β API endpoints with database
- Hardware tests β Camera and fingerprint sensor on Pi 5
# Activate virtual environment
source venv/bin/activate
# Run all tests
python -m pytest backend/tests/ -v
# Run specific module
python -m pytest backend/tests/test_auth.py -v
# With coverage
python -m pytest backend/tests/ --cov=backend --cov-report=html| Module | Tests |
|---|---|
backend/auth/password.py |
Hash/verify password, bcrypt rounds |
backend/auth/jwt_handler.py |
Token creation, verification, expiry |
ai_engine/face_recognizer.py |
Confidence calculation, embedding matching |
ai_engine/head_counter.py |
Model loading, person detection |
attendance_engine/session_manager.py |
Session lifecycle, duplicate prevention |
Integration tests require a running PostgreSQL instance.
# Start only the database via Docker
docker compose up -d db
# Set test database URL
export DATABASE_URL="postgresql+asyncpg://classos:classos_secret@localhost:5432/classos_db"python -m pytest backend/tests/integration/ -v-
Auth Flow:
- Login with valid credentials β receive tokens
- Login with invalid credentials β 401
- Access protected endpoint with valid token β 200
- Access protected endpoint without token β 401
- Refresh expired access token β new tokens
-
Student CRUD:
- Create student β verify in DB
- List students with pagination
- Search students by name/ID
- Create duplicate student ID β 400
-
Attendance Session:
- Start session β verify active in DB
- Start duplicate session for same course β 400
- End session β verify completed status
- Mark attendance manually
# Quick test
python3 -c "
from camera_service.camera import camera
camera.start()
import time
time.sleep(2)
frame = camera.get_latest_frame()
print('Frame shape:', frame.shape if frame is not None else 'None')
camera.stop()
print('Camera test passed!')
"# Connection test
python3 -c "
from fingerprint_service.sensor import fp_sensor
status = fp_sensor.get_status()
print('Sensor connected:', status)
print('Mock mode:', fp_sensor.mock_mode)
"# Test face detection on a sample image
python3 -c "
import cv2
from ai_engine.face_detector import detector
# Use a sample image
img = cv2.imread('test_image.jpg')
if img is not None:
faces = detector.detect_faces(img)
print(f'Detected {len(faces)} faces')
else:
print('No test image found')
"cd frontend
npm run build
# Should complete without errors- Login page renders correctly
- Login with valid credentials redirects to dashboard
- Login with invalid credentials shows error
- Sidebar navigation works for all pages
- Dark/light theme toggle works
- Student list loads and displays data
- Add student modal creates student
- Course list loads
- Add course modal creates course
- Attendance page shows course selector
- Start session activates camera feed
- WebSocket connection established (green indicator)
- Attendance log updates in real-time
- End session stops camera feed
- Analytics charts render
- Settings page shows profile and theme toggle
Full workflow test (requires Pi 5 with hardware):
- Login as admin β Create a teacher account
- Login as teacher β Create a course
- Register a student β Capture 20 face samples β Enroll fingerprint
- Enroll student in course
- Start attendance session
- Stand in front of camera β Verify face recognition
- Cover face β Verify fingerprint prompt appears
- Use fingerprint sensor β Verify attendance marked
- End session β Verify attendance records in DB
- Check analytics page β Verify charts updated