Fix tests after refactor

This commit is contained in:
Pim van Pelt
2025-08-03 11:43:53 +02:00
parent f1d10458c6
commit 64e1ca124f
5 changed files with 60 additions and 48 deletions

View File

@@ -21,7 +21,7 @@ class TestCLIIntegration:
# Verify parser is created
assert monitor_parser is not None
assert hasattr(setup_monitor_parser, "_parser")
assert monitor_parser.prog.endswith("monitor")
def test_maintenance_parser_setup(self):
"""Test maintenance parser setup"""
@@ -32,7 +32,7 @@ class TestCLIIntegration:
# Verify parser is created
assert maintenance_parser is not None
assert hasattr(setup_maintenance_parser, "_parser")
assert maintenance_parser.prog.endswith("maintenance")
def test_info_parser_setup(self):
"""Test info parser setup"""
@@ -50,16 +50,13 @@ class TestCLIIntegration:
mock_args = Mock()
mock_args.monitor_action = None
# Setup parser reference
mock_parser = Mock()
setup_monitor_parser._parser = mock_parser
# Execute
result = handle_monitor_command(mock_args, mock_client)
# Verify
assert result is False
mock_parser.print_help.assert_called_once()
captured = capsys.readouterr()
assert "Error: No monitor action specified" in captured.out
def test_maintenance_help_message(self, mock_client, capsys):
"""Test maintenance command shows help when no action specified"""
@@ -67,16 +64,13 @@ class TestCLIIntegration:
mock_args = Mock()
mock_args.maintenance_action = None
# Setup parser reference
mock_parser = Mock()
setup_maintenance_parser._parser = mock_parser
# Execute
result = handle_maintenance_command(mock_args, mock_client)
# Verify
assert result is False
mock_parser.print_help.assert_called_once()
captured = capsys.readouterr()
assert "Error: No maintenance action specified" in captured.out
def test_monitor_command_with_full_args(self, mock_client):
"""Test monitor command with complete argument structure"""
@@ -87,11 +81,9 @@ class TestCLIIntegration:
mock_args.group = ["web-services"]
# Mock client methods
mock_client.find_monitors_by_pattern.return_value = [
{"id": 1, "name": "test-monitor"}
]
mock_client.get_monitors_in_groups.return_value = [
{"id": 2, "name": "web-service-monitor"}
mock_client.find_and_get_monitors.return_value = [
{"id": 1, "name": "test-monitor"},
{"id": 2, "name": "web-service-monitor"},
]
mock_client.api.pause_monitor.return_value = {"msg": "Paused Successfully."}
@@ -100,8 +92,9 @@ class TestCLIIntegration:
# Verify
assert result is True
mock_client.find_monitors_by_pattern.assert_called_once_with(["test*"])
mock_client.get_monitors_in_groups.assert_called_once_with(["web-services"])
mock_client.find_and_get_monitors.assert_called_once_with(
["test*"], ["web-services"]
)
# Should pause both monitors (deduplicated)
assert mock_client.api.pause_monitor.call_count == 2
@@ -235,7 +228,11 @@ class TestErrorHandling:
mock_args.group = None
# Mock no matches found
mock_client.find_monitors_by_pattern.return_value = []
def mock_find_and_get_monitors(*args, **kwargs):
print("Error: No monitors found matching the specified patterns or groups")
return []
mock_client.find_and_get_monitors.side_effect = mock_find_and_get_monitors
# Execute
result = handle_monitor_command(mock_args, mock_client)
@@ -255,7 +252,11 @@ class TestErrorHandling:
mock_args.maintenance_action = "list"
# Mock API error
mock_client.api.get_maintenances.side_effect = Exception("Connection timeout")
from uptime_kuma_api import UptimeKumaException
mock_client.api.get_maintenances.side_effect = UptimeKumaException(
"Connection timeout"
)
# Execute
result = handle_maintenance_command(mock_args, mock_client)