Skip to content

test : add unit tests for main.py exception handlers #1725

Description

@tmdeveloper007

Summary of What Needs to be Done:
backend/secuscan/main.py contains several exception handler functions and redirect functions that have no test coverage. No test file exists for main.py. The testable functions include:

  • rate_limit_exceeded_handler: handles RateLimitExceeded exceptions
  • generic_rate_limit_handler: handles generic exceptions as rate limit
  • custom_http_exception_handler: handles StarletteHTTPException
  • custom_validation_exception_handler: handles RequestValidationError
  • custom_unhandled_exception_handler: handles unexpected exceptions
  • redirect_api_docs / redirect_api_redoc / redirect_api_openapi: redirect to root
  • health_check: returns basic health status
  • root: returns API root information

Changes that Need to be Made:
Create testing/backend/unit/test_main.py using FastAPI TestClient. Test each handler by:

  • Calling the handler with a mock Request and appropriate Exception
  • Asserting the response status code and body content

Impact that it would Provide:

  • Reliability: ensures error responses are correctly formatted for all error types
  • Coverage: adds tests for a module that is currently completely untested
  • Prevents regressions in error handling behavior

Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions