Standardize API response envelopes: use items for collection responses and update tests
This commit is contained in:
@@ -381,7 +381,7 @@ class TestListInactiveJails:
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
|
||||
names = [j.name for j in result.jails]
|
||||
names = [j.name for j in result.items]
|
||||
assert "sshd" not in names
|
||||
assert "apache-auth" in names
|
||||
|
||||
@@ -393,7 +393,7 @@ class TestListInactiveJails:
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
|
||||
assert result.total == len(result.jails)
|
||||
assert result.total == len(result.items)
|
||||
|
||||
async def test_empty_config_dir(self, tmp_path: Path) -> None:
|
||||
with patch(
|
||||
@@ -402,7 +402,7 @@ class TestListInactiveJails:
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
|
||||
assert result.jails == []
|
||||
assert result.items == []
|
||||
assert result.total == 0
|
||||
|
||||
async def test_all_active_returns_empty(self, tmp_path: Path) -> None:
|
||||
@@ -413,7 +413,7 @@ class TestListInactiveJails:
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
|
||||
assert result.jails == []
|
||||
assert result.items == []
|
||||
|
||||
async def test_fail2ban_unreachable_shows_all(self, tmp_path: Path) -> None:
|
||||
# When fail2ban is unreachable, _get_active_jail_names returns empty set,
|
||||
@@ -425,7 +425,7 @@ class TestListInactiveJails:
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
|
||||
names = {j.name for j in result.jails}
|
||||
names = {j.name for j in result.items}
|
||||
assert "sshd" in names
|
||||
assert "apache-auth" in names
|
||||
|
||||
@@ -440,7 +440,7 @@ class TestListInactiveJails:
|
||||
new=AsyncMock(return_value=set()),
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
jail = next(j for j in result.jails if j.name == "apache-auth")
|
||||
jail = next(j for j in result.items if j.name == "apache-auth")
|
||||
assert jail.has_local_override is True
|
||||
|
||||
async def test_has_local_override_false_when_no_local_file(self, tmp_path: Path) -> None:
|
||||
@@ -451,7 +451,7 @@ class TestListInactiveJails:
|
||||
new=AsyncMock(return_value=set()),
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
jail = next(j for j in result.jails if j.name == "apache-auth")
|
||||
jail = next(j for j in result.items if j.name == "apache-auth")
|
||||
assert jail.has_local_override is False
|
||||
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ class TestListJailConfigs:
|
||||
|
||||
assert isinstance(result, JailConfigListResponse)
|
||||
assert result.total == 1
|
||||
assert result.jails[0].name == "sshd"
|
||||
assert result.items[0].name == "sshd"
|
||||
|
||||
async def test_empty_when_no_jails(self) -> None:
|
||||
"""list_jail_configs returns empty list when no jails are active."""
|
||||
@@ -229,7 +229,7 @@ class TestListJailConfigs:
|
||||
result = await config_service.list_jail_configs(_SOCKET)
|
||||
|
||||
assert result.total == 0
|
||||
assert result.jails == []
|
||||
assert result.items == []
|
||||
|
||||
async def test_multiple_jails(self) -> None:
|
||||
"""list_jail_configs handles comma-separated jail names."""
|
||||
@@ -245,7 +245,7 @@ class TestListJailConfigs:
|
||||
result = await config_service.list_jail_configs(_SOCKET)
|
||||
|
||||
assert result.total == 2
|
||||
names = {j.name for j in result.jails}
|
||||
names = {j.name for j in result.items}
|
||||
assert names == {"sshd", "nginx"}
|
||||
|
||||
|
||||
@@ -887,7 +887,7 @@ class TestConfigModuleIntegration:
|
||||
):
|
||||
result = await list_inactive_jails(str(tmp_path), "/fake.sock")
|
||||
|
||||
names = {j.name for j in result.jails}
|
||||
names = {j.name for j in result.items}
|
||||
assert "apache-auth" in names
|
||||
assert "sshd" not in names
|
||||
|
||||
|
||||
Reference in New Issue
Block a user