refactor(tests): remove duplicate fixture in test_array.py, unify on _mock_graphql

This commit is contained in:
Jacob Magar
2026-03-15 19:32:17 -04:00
parent 6eafc16af7
commit b68347bc1e

View File

@@ -148,18 +148,12 @@ class TestArrayNetworkErrors:
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@pytest.fixture
def _mock_array_graphql():
with patch("unraid_mcp.tools.array.make_graphql_request", new_callable=AsyncMock) as m:
yield m
# parity_history # parity_history
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_parity_history_returns_history(_mock_array_graphql): async def test_parity_history_returns_history(_mock_graphql):
_mock_array_graphql.return_value = { _mock_graphql.return_value = {
"parityHistory": [{"date": "2026-03-01T00:00:00Z", "status": "COMPLETED", "errors": 0}] "parityHistory": [{"date": "2026-03-01T00:00:00Z", "status": "COMPLETED", "errors": 0}]
} }
result = await _make_tool()(action="parity_history") result = await _make_tool()(action="parity_history")
@@ -171,15 +165,15 @@ async def test_parity_history_returns_history(_mock_array_graphql):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_start_array(_mock_array_graphql): async def test_start_array(_mock_graphql):
_mock_array_graphql.return_value = {"array": {"setState": {"state": "STARTED"}}} _mock_graphql.return_value = {"array": {"setState": {"state": "STARTED"}}}
result = await _make_tool()(action="start_array") result = await _make_tool()(action="start_array")
assert result["success"] is True assert result["success"] is True
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_stop_array(_mock_array_graphql): async def test_stop_array(_mock_graphql):
_mock_array_graphql.return_value = {"array": {"setState": {"state": "STOPPED"}}} _mock_graphql.return_value = {"array": {"setState": {"state": "STOPPED"}}}
result = await _make_tool()(action="stop_array") result = await _make_tool()(action="stop_array")
assert result["success"] is True assert result["success"] is True
@@ -188,14 +182,14 @@ async def test_stop_array(_mock_array_graphql):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_add_disk_requires_disk_id(_mock_array_graphql): async def test_add_disk_requires_disk_id(_mock_graphql):
with pytest.raises(ToolError, match="disk_id"): with pytest.raises(ToolError, match="disk_id"):
await _make_tool()(action="add_disk") await _make_tool()(action="add_disk")
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_add_disk_success(_mock_array_graphql): async def test_add_disk_success(_mock_graphql):
_mock_array_graphql.return_value = {"array": {"addDiskToArray": {"state": "STARTED"}}} _mock_graphql.return_value = {"array": {"addDiskToArray": {"state": "STARTED"}}}
result = await _make_tool()(action="add_disk", disk_id="abc123:local") result = await _make_tool()(action="add_disk", disk_id="abc123:local")
assert result["success"] is True assert result["success"] is True
@@ -204,14 +198,14 @@ async def test_add_disk_success(_mock_array_graphql):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_remove_disk_requires_confirm(_mock_array_graphql): async def test_remove_disk_requires_confirm(_mock_graphql):
with pytest.raises(ToolError, match="not confirmed"): with pytest.raises(ToolError, match="not confirmed"):
await _make_tool()(action="remove_disk", disk_id="abc123:local", confirm=False) await _make_tool()(action="remove_disk", disk_id="abc123:local", confirm=False)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_remove_disk_with_confirm(_mock_array_graphql): async def test_remove_disk_with_confirm(_mock_graphql):
_mock_array_graphql.return_value = {"array": {"removeDiskFromArray": {"state": "STOPPED"}}} _mock_graphql.return_value = {"array": {"removeDiskFromArray": {"state": "STOPPED"}}}
result = await _make_tool()(action="remove_disk", disk_id="abc123:local", confirm=True) result = await _make_tool()(action="remove_disk", disk_id="abc123:local", confirm=True)
assert result["success"] is True assert result["success"] is True
@@ -220,14 +214,14 @@ async def test_remove_disk_with_confirm(_mock_array_graphql):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_mount_disk_requires_disk_id(_mock_array_graphql): async def test_mount_disk_requires_disk_id(_mock_graphql):
with pytest.raises(ToolError, match="disk_id"): with pytest.raises(ToolError, match="disk_id"):
await _make_tool()(action="mount_disk") await _make_tool()(action="mount_disk")
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_unmount_disk_success(_mock_array_graphql): async def test_unmount_disk_success(_mock_graphql):
_mock_array_graphql.return_value = {"array": {"unmountArrayDisk": {"id": "abc123:local"}}} _mock_graphql.return_value = {"array": {"unmountArrayDisk": {"id": "abc123:local"}}}
result = await _make_tool()(action="unmount_disk", disk_id="abc123:local") result = await _make_tool()(action="unmount_disk", disk_id="abc123:local")
assert result["success"] is True assert result["success"] is True
@@ -236,13 +230,13 @@ async def test_unmount_disk_success(_mock_array_graphql):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_clear_disk_stats_requires_confirm(_mock_array_graphql): async def test_clear_disk_stats_requires_confirm(_mock_graphql):
with pytest.raises(ToolError, match="not confirmed"): with pytest.raises(ToolError, match="not confirmed"):
await _make_tool()(action="clear_disk_stats", disk_id="abc123:local", confirm=False) await _make_tool()(action="clear_disk_stats", disk_id="abc123:local", confirm=False)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_clear_disk_stats_with_confirm(_mock_array_graphql): async def test_clear_disk_stats_with_confirm(_mock_graphql):
_mock_array_graphql.return_value = {"array": {"clearArrayDiskStatistics": True}} _mock_graphql.return_value = {"array": {"clearArrayDiskStatistics": True}}
result = await _make_tool()(action="clear_disk_stats", disk_id="abc123:local", confirm=True) result = await _make_tool()(action="clear_disk_stats", disk_id="abc123:local", confirm=True)
assert result["success"] is True assert result["success"] is True