Skip to content

test : add unit tests for logging_utils JSONFormatter and RequestIDFilter #1201

Description

@tmdeveloper007

Summary of What Needs to be Done:
backend/secuscan/logging_utils.py has partial test coverage: existing tests cover basic serialization and exception formatting, but several edge cases are untested. The JSONFormatter does not handle a missing request_id attribute gracefully in all paths, and the RequestIDFilter has untested behavior for the no-request-id case.

Changes that Need to be Made:

  • Add testing/backend/unit/test_logging_utils_extended.py
  • Test JSONFormatter.format when record lacks request_id attribute entirely
  • Test JSONFormatter.format when record.request_id is None vs missing attribute
  • Test RequestIDFilter.filter: sets record.request_id to get_request_id() result
  • Test RequestIDFilter.filter when get_request_id returns None
  • Test JSONFormatter with a record that has all fields populated (complete integration)
  • Use monkeypatch to patch get_request_id for isolation

Impact that it would Provide:

  • Ensures log output is always well-formed JSON even with unusual log records
  • Validates request ID injection in multi-threaded logging scenarios
  • Improves debuggability of production log output

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