22Events Feed Test Module
33"""
44
5+ import os
56from http import HTTPStatus
67from tools .events_feed .tool import EventsFeedTools
7- from utils .app_config import AppConfig
8- from .conftest import util_load_json
9- from unittest .mock import MagicMock , AsyncMock , create_autospec
10- from sysdig_client .api import SecureEventsApi
11- import os
8+ from unittest .mock import MagicMock , AsyncMock
129from fastmcp .server .context import Context
1310from fastmcp .server import FastMCP
11+ from .conftest import util_load_json , mock_app_config
1412
1513# Get the absolute path of the current module file
1614module_path = os .path .abspath (__file__ )
2018
2119EVENT_INFO_RESPONSE = util_load_json (f"{ module_directory } /test_data/events_feed/event_info_response.json" )
2220
21+ ctx = Context (MagicMock (spec = FastMCP ))
2322
24- def mock_app_config () -> AppConfig :
25- mock_cfg = create_autospec (AppConfig , instance = True )
26-
27- mock_cfg .sysdig_endpoint .return_value = "https://us2.app.sysdig.com"
28- mock_cfg .transport .return_value = "stdio"
29- mock_cfg .log_level .return_value = "DEBUG"
30- mock_cfg .port .return_value = 8080
31-
32- return mock_cfg
3323
34- def test_get_event_info (mock_success_response : MagicMock | AsyncMock , mock_creds ) -> None :
24+ def test_get_event_info (mock_success_response : MagicMock | AsyncMock , mock_creds , mock_context : Context ) -> None :
3525 """Test the get_event_info tool method.
3626 Args:
3727 mock_success_response (MagicMock | AsyncMock): Mocked response object.
@@ -43,22 +33,8 @@ def test_get_event_info(mock_success_response: MagicMock | AsyncMock, mock_creds
4333
4434 tools_client = EventsFeedTools (app_config = mock_app_config ())
4535
46- ctx = Context (FastMCP ())
47-
48- # Seed FastMCP Context state with mocked API instances expected by the tools
49- secure_events_api = MagicMock (spec = SecureEventsApi )
50- # The tool returns whatever the SDK method returns; make it be our mocked HTTP response
51- secure_events_api .get_event_v1_without_preload_content .return_value = mock_success_response .return_value
52-
53- api_instances = {
54- "secure_events" : secure_events_api ,
55- # Not used by this test, but present in real runtime; keep as empty mock to avoid KeyErrors elsewhere
56- "legacy_sysdig_api" : MagicMock (),
57- }
58- ctx .set_state ("api_instances" , api_instances )
59-
6036 # Pass the mocked Context object
61- result : dict = tools_client .tool_get_event_info (ctx = ctx , event_id = "12345" )
37+ result : dict = tools_client .tool_get_event_info (ctx = mock_context , event_id = "12345" )
6238 results : dict = result ["results" ]
6339
6440 assert result .get ("status_code" ) == HTTPStatus .OK
0 commit comments