Skip to content

test: add 100% coverage for app/main.py

Kuruva Laxmi requested to merge fix/main-coverage into main

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

  • /login redirect to / when auth token exists (302)
  • /login?logout=true behavior validation
  • No-token login scenario coverage

🎙/api/transcribe Tests

  • file_url success 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_subtitles failure → 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

Screenshot image

Merge request reports

Loading