Reformat with black
This commit is contained in:
@@ -11,7 +11,7 @@ class TestKumaClient:
|
||||
def test_parse_duration_minutes(self):
|
||||
"""Test parsing duration in minutes"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
assert client.parse_duration("90m") == 5400 # 90 * 60
|
||||
assert client.parse_duration("1m") == 60
|
||||
assert client.parse_duration("120m") == 7200
|
||||
@@ -19,7 +19,7 @@ class TestKumaClient:
|
||||
def test_parse_duration_hours(self):
|
||||
"""Test parsing duration in hours"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
assert client.parse_duration("1h") == 3600 # 1 * 3600
|
||||
assert client.parse_duration("2h") == 7200
|
||||
assert client.parse_duration("24h") == 86400
|
||||
@@ -27,7 +27,7 @@ class TestKumaClient:
|
||||
def test_parse_duration_seconds(self):
|
||||
"""Test parsing duration in seconds"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
assert client.parse_duration("3600s") == 3600
|
||||
assert client.parse_duration("60s") == 60
|
||||
assert client.parse_duration("1s") == 1
|
||||
@@ -35,42 +35,42 @@ class TestKumaClient:
|
||||
def test_parse_duration_default(self):
|
||||
"""Test parsing duration with default value"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
assert client.parse_duration(None) == 5400 # Default 90 minutes
|
||||
assert client.parse_duration("") == 5400
|
||||
|
||||
def test_parse_duration_invalid(self):
|
||||
"""Test parsing invalid duration format"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid duration format"):
|
||||
client.parse_duration("invalid")
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid duration format"):
|
||||
client.parse_duration("90x")
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid duration format"):
|
||||
client.parse_duration("90")
|
||||
|
||||
def test_parse_start_time_none(self):
|
||||
"""Test parsing start time with None (current time)"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
before = datetime.utcnow()
|
||||
result = client.parse_start_time(None)
|
||||
after = datetime.utcnow()
|
||||
|
||||
|
||||
assert before <= result <= after
|
||||
|
||||
def test_parse_start_time_iso_format(self):
|
||||
"""Test parsing ISO format start time"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
# Test ISO format with Z
|
||||
result = client.parse_start_time("2023-12-25T10:30:00Z")
|
||||
expected = datetime(2023, 12, 25, 10, 30, 0)
|
||||
assert result == expected
|
||||
|
||||
|
||||
# Test ISO format with timezone
|
||||
result = client.parse_start_time("2023-12-25T10:30:00+00:00")
|
||||
assert result == expected
|
||||
@@ -78,17 +78,17 @@ class TestKumaClient:
|
||||
def test_parse_start_time_common_formats(self):
|
||||
"""Test parsing common date/time formats"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
# Full datetime
|
||||
result = client.parse_start_time("2023-12-25 10:30:00")
|
||||
expected = datetime(2023, 12, 25, 10, 30, 0)
|
||||
assert result == expected
|
||||
|
||||
|
||||
# Date and hour:minute
|
||||
result = client.parse_start_time("2023-12-25 10:30")
|
||||
expected = datetime(2023, 12, 25, 10, 30, 0)
|
||||
assert result == expected
|
||||
|
||||
|
||||
# Date only
|
||||
result = client.parse_start_time("2023-12-25")
|
||||
expected = datetime(2023, 12, 25, 0, 0, 0)
|
||||
@@ -97,10 +97,10 @@ class TestKumaClient:
|
||||
def test_parse_start_time_invalid(self):
|
||||
"""Test parsing invalid start time format"""
|
||||
client = KumaClient("http://test.com")
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid start time format"):
|
||||
client.parse_start_time("invalid-date")
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match="Invalid start time format"):
|
||||
client.parse_start_time("2023-13-45")
|
||||
|
||||
@@ -108,20 +108,20 @@ class TestKumaClient:
|
||||
"""Test finding monitors by pattern successfully"""
|
||||
client = KumaClient("http://test.com")
|
||||
client.api = Mock()
|
||||
|
||||
|
||||
mock_monitors = [
|
||||
{"id": 1, "name": "Web Server"},
|
||||
{"id": 2, "name": "API Server"},
|
||||
{"id": 3, "name": "Database"},
|
||||
{"id": 4, "name": "Web Frontend"}
|
||||
{"id": 4, "name": "Web Frontend"},
|
||||
]
|
||||
client.api.get_monitors.return_value = mock_monitors
|
||||
|
||||
|
||||
# Test exact match
|
||||
result = client.find_monitors_by_pattern(["Web Server"])
|
||||
assert len(result) == 1
|
||||
assert result[0]["name"] == "Web Server"
|
||||
|
||||
|
||||
# Test wildcard pattern
|
||||
result = client.find_monitors_by_pattern(["Web*"])
|
||||
assert len(result) == 2
|
||||
@@ -133,13 +133,13 @@ class TestKumaClient:
|
||||
"""Test finding monitors by pattern is case insensitive"""
|
||||
client = KumaClient("http://test.com")
|
||||
client.api = Mock()
|
||||
|
||||
|
||||
mock_monitors = [
|
||||
{"id": 1, "name": "Web Server"},
|
||||
{"id": 2, "name": "API Server"}
|
||||
{"id": 2, "name": "API Server"},
|
||||
]
|
||||
client.api.get_monitors.return_value = mock_monitors
|
||||
|
||||
|
||||
# Test case insensitive matching
|
||||
result = client.find_monitors_by_pattern(["web*"])
|
||||
assert len(result) == 1
|
||||
@@ -149,12 +149,10 @@ class TestKumaClient:
|
||||
"""Test finding monitors with no matches"""
|
||||
client = KumaClient("http://test.com")
|
||||
client.api = Mock()
|
||||
|
||||
mock_monitors = [
|
||||
{"id": 1, "name": "Web Server"}
|
||||
]
|
||||
|
||||
mock_monitors = [{"id": 1, "name": "Web Server"}]
|
||||
client.api.get_monitors.return_value = mock_monitors
|
||||
|
||||
|
||||
result = client.find_monitors_by_pattern(["Database*"])
|
||||
assert len(result) == 0
|
||||
|
||||
@@ -162,12 +160,10 @@ class TestKumaClient:
|
||||
"""Test finding monitors removes duplicates"""
|
||||
client = KumaClient("http://test.com")
|
||||
client.api = Mock()
|
||||
|
||||
mock_monitors = [
|
||||
{"id": 1, "name": "Web Server"}
|
||||
]
|
||||
|
||||
mock_monitors = [{"id": 1, "name": "Web Server"}]
|
||||
client.api.get_monitors.return_value = mock_monitors
|
||||
|
||||
|
||||
# Same monitor should match both patterns
|
||||
result = client.find_monitors_by_pattern(["Web*", "*Server"])
|
||||
assert len(result) == 1
|
||||
@@ -177,41 +173,41 @@ class TestKumaClient:
|
||||
"""Test finding monitors handles API errors"""
|
||||
client = KumaClient("http://test.com")
|
||||
client.api = Mock()
|
||||
|
||||
|
||||
client.api.get_monitors.side_effect = Exception("API Error")
|
||||
|
||||
|
||||
result = client.find_monitors_by_pattern(["Web*"])
|
||||
assert len(result) == 0
|
||||
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "Error finding monitors: API Error" in captured.out
|
||||
|
||||
@patch('kumacli.client.UptimeKumaApi')
|
||||
@patch("kumacli.client.UptimeKumaApi")
|
||||
def test_connect_success(self, mock_api_class, capsys):
|
||||
"""Test successful connection"""
|
||||
mock_api = Mock()
|
||||
mock_api_class.return_value = mock_api
|
||||
mock_api.login.return_value = True
|
||||
|
||||
|
||||
client = KumaClient("http://test.com", "user", "pass")
|
||||
result = client.connect()
|
||||
|
||||
|
||||
assert result is True
|
||||
assert client.api is mock_api
|
||||
mock_api_class.assert_called_once_with("http://test.com")
|
||||
mock_api.login.assert_called_once_with("user", "pass")
|
||||
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "Connected to http://test.com" in captured.out
|
||||
|
||||
@patch('kumacli.client.UptimeKumaApi')
|
||||
@patch("kumacli.client.UptimeKumaApi")
|
||||
def test_connect_failure(self, mock_api_class, capsys):
|
||||
"""Test connection failure"""
|
||||
mock_api_class.side_effect = Exception("Connection failed")
|
||||
|
||||
|
||||
client = KumaClient("http://test.com", "user", "pass")
|
||||
result = client.connect()
|
||||
|
||||
|
||||
assert result is False
|
||||
captured = capsys.readouterr()
|
||||
assert "Failed to connect: Connection failed" in captured.out
|
||||
@@ -220,7 +216,7 @@ class TestKumaClient:
|
||||
"""Test disconnection"""
|
||||
client = KumaClient("http://test.com")
|
||||
client.api = Mock()
|
||||
|
||||
|
||||
client.disconnect()
|
||||
|
||||
client.api.disconnect.assert_called_once()
|
||||
|
||||
client.api.disconnect.assert_called_once()
|
||||
|
Reference in New Issue
Block a user