Refactor service status response: migrate bangui_version into version field
This commit is contained in:
@@ -1001,8 +1001,7 @@ class ServiceStatusResponse(BaseModel):
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
online: bool = Field(..., description="Whether fail2ban is reachable via its socket.")
|
||||
version: str | None = Field(default=None, description="fail2ban version string, or None when offline.")
|
||||
bangui_version: str = Field(..., description="BanGUI application version.")
|
||||
version: str | None = Field(default=None, description="BanGUI application version (or None when offline).")
|
||||
jail_count: int = Field(default=0, ge=0, description="Number of currently active jails.")
|
||||
total_bans: int = Field(default=0, ge=0, description="Aggregated current ban count across all jails.")
|
||||
total_failures: int = Field(default=0, ge=0, description="Aggregated current failure count across all jails.")
|
||||
|
||||
@@ -24,7 +24,6 @@ class ServerStatusResponse(BaseModel):
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
status: ServerStatus
|
||||
bangui_version: str = Field(..., description="BanGUI application version.")
|
||||
|
||||
|
||||
class ServerSettings(BaseModel):
|
||||
|
||||
@@ -70,7 +70,8 @@ async def get_server_status(
|
||||
"server_status",
|
||||
ServerStatus(online=False),
|
||||
)
|
||||
return ServerStatusResponse(status=cached, bangui_version=__version__)
|
||||
cached.version = __version__
|
||||
return ServerStatusResponse(status=cached)
|
||||
|
||||
|
||||
@router.get(
|
||||
|
||||
@@ -819,8 +819,7 @@ async def get_service_status(
|
||||
|
||||
return ServiceStatusResponse(
|
||||
online=server_status.online,
|
||||
version=server_status.version,
|
||||
bangui_version=__version__,
|
||||
version=__version__,
|
||||
jail_count=server_status.active_jails,
|
||||
total_bans=server_status.total_bans,
|
||||
total_failures=server_status.total_failures,
|
||||
|
||||
@@ -221,8 +221,8 @@ class TestFilterConfigImports:
|
||||
|
||||
|
||||
class TestServiceStatusBanguiVersion:
|
||||
"""Bug 4: ``get_service_status`` must include ``bangui_version``
|
||||
in the ``ServiceStatusResponse`` it returns."""
|
||||
"""Bug 4: ``get_service_status`` must include application version
|
||||
in the ``version`` field of the ``ServiceStatusResponse``."""
|
||||
|
||||
async def test_online_response_contains_bangui_version(self) -> None:
|
||||
"""The returned model must contain the ``bangui_version`` field."""
|
||||
@@ -256,11 +256,9 @@ class TestServiceStatusBanguiVersion:
|
||||
probe_fn=AsyncMock(return_value=online_status),
|
||||
)
|
||||
|
||||
assert hasattr(result, "bangui_version"), (
|
||||
"ServiceStatusResponse is missing bangui_version — "
|
||||
"Pydantic will raise ValidationError → 500"
|
||||
assert result.version == app.__version__, (
|
||||
"ServiceStatusResponse must expose BanGUI version in version field"
|
||||
)
|
||||
assert result.bangui_version == app.__version__
|
||||
|
||||
async def test_offline_response_contains_bangui_version(self) -> None:
|
||||
"""Even when fail2ban is offline, ``bangui_version`` must be present."""
|
||||
@@ -275,4 +273,4 @@ class TestServiceStatusBanguiVersion:
|
||||
probe_fn=AsyncMock(return_value=offline_status),
|
||||
)
|
||||
|
||||
assert result.bangui_version == app.__version__
|
||||
assert result.version == app.__version__
|
||||
|
||||
@@ -2001,8 +2001,7 @@ class TestGetServiceStatus:
|
||||
def _mock_status(self, online: bool = True) -> ServiceStatusResponse:
|
||||
return ServiceStatusResponse(
|
||||
online=online,
|
||||
version="1.0.0" if online else None,
|
||||
bangui_version=app.__version__,
|
||||
version=app.__version__,
|
||||
jail_count=2 if online else 0,
|
||||
total_bans=10 if online else 0,
|
||||
total_failures=3 if online else 0,
|
||||
@@ -2021,7 +2020,7 @@ class TestGetServiceStatus:
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["online"] is True
|
||||
assert data["bangui_version"] == app.__version__
|
||||
assert data["version"] == app.__version__
|
||||
assert data["jail_count"] == 2
|
||||
assert data["log_level"] == "INFO"
|
||||
|
||||
@@ -2035,7 +2034,7 @@ class TestGetServiceStatus:
|
||||
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["bangui_version"] == app.__version__
|
||||
assert data["version"] == app.__version__
|
||||
assert data["online"] is False
|
||||
assert data["log_level"] == "UNKNOWN"
|
||||
|
||||
|
||||
@@ -153,8 +153,6 @@ class TestDashboardStatus:
|
||||
body = response.json()
|
||||
|
||||
assert "status" in body
|
||||
assert "bangui_version" in body
|
||||
assert body["bangui_version"] == app.__version__
|
||||
|
||||
status = body["status"]
|
||||
assert "online" in status
|
||||
@@ -171,9 +169,8 @@ class TestDashboardStatus:
|
||||
body = response.json()
|
||||
status = body["status"]
|
||||
|
||||
assert body["bangui_version"] == app.__version__
|
||||
assert status["online"] is True
|
||||
assert status["version"] == "1.0.2"
|
||||
assert status["version"] == app.__version__
|
||||
assert status["active_jails"] == 2
|
||||
assert status["total_bans"] == 10
|
||||
assert status["total_failures"] == 5
|
||||
@@ -187,9 +184,8 @@ class TestDashboardStatus:
|
||||
body = response.json()
|
||||
status = body["status"]
|
||||
|
||||
assert body["bangui_version"] == app.__version__
|
||||
assert status["online"] is False
|
||||
assert status["version"] is None
|
||||
assert status["version"] == app.__version__
|
||||
assert status["active_jails"] == 0
|
||||
assert status["total_bans"] == 0
|
||||
assert status["total_failures"] == 0
|
||||
|
||||
@@ -752,8 +752,7 @@ class TestGetServiceStatus:
|
||||
from app import __version__
|
||||
|
||||
assert result.online is True
|
||||
assert result.version == "1.0.0"
|
||||
assert result.bangui_version == __version__
|
||||
assert result.version == __version__
|
||||
assert result.jail_count == 2
|
||||
assert result.total_bans == 5
|
||||
assert result.total_failures == 3
|
||||
|
||||
Reference in New Issue
Block a user