1818from unittest .mock import MagicMock , patch
1919
2020import pytest
21-
2221from datacommons_mcp .app import DCApp
2322
2423
2524@pytest .fixture
2625def mock_settings ():
26+ from datacommons_mcp .data_models .settings import BaseDCSettings
27+
2728 with patch ("datacommons_mcp.app.settings.get_dc_settings" ) as mock :
28- mock .return_value = MagicMock (instructions_dir = None , api_key = "test-key" )
29+ # Return a real BaseDCSettings object
30+ mock .return_value = BaseDCSettings (api_key = "test-key" )
2931 yield mock
3032
3133
@@ -44,7 +46,7 @@ def mock_fastmcp():
4446 yield mock
4547
4648
47- def test_app_initialization_default (mock_settings , mock_client , mock_fastmcp ):
49+ def test_app_initialization_default (mock_settings , mock_fastmcp ): # noqa: ARG001
4850 """Test that DCApp initializes with default instructions."""
4951 _ = DCApp ()
5052
@@ -56,7 +58,7 @@ def test_app_initialization_default(mock_settings, mock_client, mock_fastmcp):
5658
5759
5860def test_app_initialization_override (
59- mock_settings , mock_client , mock_fastmcp , tmp_path , create_test_file
61+ mock_settings , mock_fastmcp , tmp_path , create_test_file
6062):
6163 """Test that DCApp loads instructions from DC_INSTRUCTIONS_DIR."""
6264 # Create custom instructions
@@ -74,9 +76,7 @@ def test_app_initialization_override(
7476 assert instructions == "Custom Server Instructions"
7577
7678
77- def test_load_instruction_tool_override (
78- mock_settings , mock_client , mock_fastmcp , tmp_path , create_test_file
79- ):
79+ def test_load_instruction_tool_override (mock_settings , tmp_path , create_test_file ):
8080 """Test loading tool instructions with override."""
8181 # Create custom instructions
8282 custom_dir = tmp_path / "instructions"
@@ -90,7 +90,7 @@ def test_load_instruction_tool_override(
9090 assert content == "Custom Tool Instructions"
9191
9292
93- def test_load_instruction_fallback (mock_settings , mock_client , mock_fastmcp , tmp_path ):
93+ def test_load_instruction_fallback (mock_settings , tmp_path ):
9494 """Test that override falls back to default if file likely doesn't exist."""
9595 # Create custom dir but empty
9696 custom_dir = tmp_path / "instructions"
@@ -100,15 +100,13 @@ def test_load_instruction_fallback(mock_settings, mock_client, mock_fastmcp, tmp
100100 mock_settings .return_value .instructions_dir = str (custom_dir )
101101
102102 app = DCApp ()
103-
103+
104104 # Should fall back to default package resource (server.md exists in package)
105105 content = app ._load_instruction ("server.md" )
106106 assert "Data Commons" in content
107107
108108
109- def test_register_tool (
110- mock_settings , mock_client , mock_fastmcp , tmp_path , create_test_file
111- ):
109+ def test_register_tool (mock_settings , mock_fastmcp , tmp_path , create_test_file ):
112110 """Test tool registration with instruction loading."""
113111 # Create custom instructions
114112 create_test_file ("instructions/tools/sample.md" , "Sample Tool Description" )
@@ -124,7 +122,7 @@ def sample_tool():
124122
125123 # Verify add_tool was called
126124 mock_mcp_instance .add_tool .assert_called_once ()
127-
125+
128126 # Verify the description was loaded correctly
129127 tool_arg = mock_mcp_instance .add_tool .call_args [0 ][0 ]
130128 assert tool_arg .description == "Sample Tool Description"
0 commit comments