Skip to content

Add unit tests for AzureMonitorLogsTool #996

@yashksaini-coder

Description

@yashksaini-coder

Summary

AzureMonitorLogsTool (app/tools/AzureMonitorLogsTool/) has no unit tests. Unlike most other integration-wave tools, this one makes direct httpx calls (no dedicated service client abstraction), so the tests need to patch at the httpx level.

Context

The tool is a @tool-decorated function with:

  • _azure_available(sources) — checks connection_verified, workspace_id, and access_token in sources["azure"]
  • _azure_extract_params(sources) — maps workspace_id, access_token, endpoint, query, time_range_minutes, limit, max_results
  • The run function uses httpx.post() to query the Azure Log Analytics API — this is the call to patch in tests

The tool also enforces a hard limit (_MAX_HARD_LIMIT = 200) and a bounded limit helper. Both warrant testing.

What to implement

Create tests/tools/test_azure_monitor_logs_tool.py covering:

  1. Contract test — inherit BaseToolContract from tests/tools/conftest.py
  2. is_availableTrue when workspace_id, access_token, and connection_verified are all set; False when any is missing
  3. extract_params — assert workspace_id, access_token, endpoint, and defaults for time_range_minutes and limit are correct
  4. Bounded limit helper — unit test _bounded_limit() directly: e.g., _bounded_limit(300, 100) should return 100 (capped at _MAX_HARD_LIMIT)
  5. run happy path — patch httpx.post to return a mocked response with status 200 and a KQL result payload; assert available: True and correct log rows in output
  6. run HTTP error path — patch to return 401 or 403 and assert a graceful error dict with available: True, error: ...
  7. run unavailable path — assert available: False when called without credentials

Acceptance criteria

  • tests/tools/test_azure_monitor_logs_tool.py created
  • All seven scenarios above covered
  • make test-cov passes
  • make lint passes

References

  • Pattern: tests/tools/test_coralogix_logs_tool.py (also patches HTTP calls)
  • Tool source: app/tools/AzureMonitorLogsTool/__init__.py
  • Related integration tests: tests/integrations/test_azure_sql.py (different tool, same Azure namespace)

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerstestsTest coverage and test organization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions