test: add 100% coverage for app/main.py
issuse no:#3 (closed)
🧾 Description
This MR improves the test coverage of app/main.py from 88% to 100% by adding targeted tests for previously uncovered branches and edge cases.
The goal is to ensure all critical paths, including error handling and conditional logic, are fully validated to prevent regressions.
✨ What’s Added
🔐 Authentication Tests
-
/loginredirect to/when auth token exists (302) -
/login?logout=truebehavior validation - No-token login scenario coverage
🎙 ️ /api/transcribe Tests
-
file_urlsuccess flow - External fetch failure handling
- Valid audio input with non-empty chunks branch
📝 /api/subtitles Tests
- Valid
chunks→ successful subtitles generation - Empty chunks (
"[]") +text→ synthetic chunk path - Invalid JSON → returns 400
-
generate_subtitlesfailure → returns 400
🧪 Additional Coverage
- Covered previously untested conditional branches
- Optional:
__main__execution path (if applicable)
📊 Result
- Coverage increased: 88% → 100% (app/main.py)
- All tests passing
- Improved reliability and regression safety
🧪 How to Test
Run: pytest --cov=app.main --cov-report=term-missing
⚠ ️ Notes
- External services are mocked for deterministic testing
- Focus on branch coverage, not just line coverage
- No changes to production logic
✅ Checklist
-
Tests added for all uncovered branches -
Coverage reached 100% for app/main.py -
All tests passing -
No breaking changes
