mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 20:06:22 -05:00
Consolidating controller tests. Fixing controller test cleanup which slowed down tests significantly.
This commit is contained in:
parent
b0be30c3d6
commit
2806673e25
11 changed files with 366 additions and 970 deletions
|
|
@ -4,15 +4,32 @@ Integration tests for Controller disks API endpoints.
|
|||
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestDockerModeRejectsDisksEndpoints:
|
||||
"""All /api/disks/* endpoints should return 501 in Docker mode."""
|
||||
|
||||
@pytest.mark.parametrize("method,endpoint,payload", [
|
||||
("get", "/api/disks", None),
|
||||
("get", "/api/disks/mounts", None),
|
||||
("post", "/api/disks/mount", {"device": "/dev/sda1", "mount_point": "/media/test"}),
|
||||
("post", "/api/disks/unmount", {"mount_point": "/media/test"}),
|
||||
("get", "/api/disks/fstab", None),
|
||||
("post", "/api/disks/fstab", {"device": "/dev/sda1", "mount_point": "/media/test", "fstype": "ext4"}),
|
||||
("delete", "/api/disks/fstab/media/test", None),
|
||||
("get", "/api/disks/smart", None),
|
||||
])
|
||||
def test_disks_endpoint_rejected_in_docker(self, test_client_docker_mode, method, endpoint, payload):
|
||||
"""Docker mode rejects every disks endpoint with 501."""
|
||||
client_call = getattr(test_client_docker_mode, method)
|
||||
response = client_call(endpoint, json=payload) if payload else client_call(endpoint)
|
||||
assert response.status_code == 501
|
||||
|
||||
|
||||
class TestDisksListEndpoint:
|
||||
"""Tests for /api/disks endpoint."""
|
||||
|
||||
def test_returns_501_in_docker_mode(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.get("/api/disks")
|
||||
assert response.status_code == 501
|
||||
|
||||
def test_returns_list_in_native_mode(self, test_client):
|
||||
"""Should return list of disks in native mode."""
|
||||
with mock.patch("controller.api.disks.get_block_devices", return_value=[]):
|
||||
|
|
@ -24,11 +41,6 @@ class TestDisksListEndpoint:
|
|||
class TestMountsEndpoint:
|
||||
"""Tests for /api/disks/mounts endpoint."""
|
||||
|
||||
def test_returns_501_in_docker_mode(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.get("/api/disks/mounts")
|
||||
assert response.status_code == 501
|
||||
|
||||
def test_returns_mounts(self, test_client):
|
||||
"""Should return current mounts."""
|
||||
mock_mounts = [{"mount_point": "/media/wrolpi", "device": "/dev/sda1"}]
|
||||
|
|
@ -41,14 +53,6 @@ class TestMountsEndpoint:
|
|||
class TestMountEndpoint:
|
||||
"""Tests for /api/disks/mount endpoint."""
|
||||
|
||||
def test_returns_501_in_docker_mode(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.post(
|
||||
"/api/disks/mount",
|
||||
json={"device": "/dev/sda1", "mount_point": "/media/test"}
|
||||
)
|
||||
assert response.status_code == 501
|
||||
|
||||
def test_mounts_drive_successfully(self, test_client):
|
||||
"""Should mount drive successfully."""
|
||||
with mock.patch(
|
||||
|
|
@ -111,14 +115,6 @@ class TestMountEndpoint:
|
|||
class TestUnmountEndpoint:
|
||||
"""Tests for /api/disks/unmount endpoint."""
|
||||
|
||||
def test_returns_501_in_docker_mode(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.post(
|
||||
"/api/disks/unmount",
|
||||
json={"mount_point": "/media/test"}
|
||||
)
|
||||
assert response.status_code == 501
|
||||
|
||||
def test_unmounts_drive_successfully(self, test_client):
|
||||
"""Should unmount drive successfully."""
|
||||
with mock.patch(
|
||||
|
|
@ -135,11 +131,6 @@ class TestUnmountEndpoint:
|
|||
class TestFstabEndpoints:
|
||||
"""Tests for /api/disks/fstab endpoints."""
|
||||
|
||||
def test_list_fstab_returns_501_in_docker(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.get("/api/disks/fstab")
|
||||
assert response.status_code == 501
|
||||
|
||||
def test_list_fstab_returns_entries(self, test_client):
|
||||
"""Should return fstab entries."""
|
||||
mock_entries = [{"mount_point": "/media/wrolpi", "device": "UUID=1234"}]
|
||||
|
|
@ -148,14 +139,6 @@ class TestFstabEndpoints:
|
|||
assert response.status_code == 200
|
||||
assert response.json() == mock_entries
|
||||
|
||||
def test_add_fstab_returns_501_in_docker(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.post(
|
||||
"/api/disks/fstab",
|
||||
json={"device": "/dev/sda1", "mount_point": "/media/test", "fstype": "ext4"}
|
||||
)
|
||||
assert response.status_code == 501
|
||||
|
||||
def test_add_fstab_entry(self, test_client):
|
||||
"""Should add fstab entry."""
|
||||
with mock.patch(
|
||||
|
|
@ -168,20 +151,10 @@ class TestFstabEndpoints:
|
|||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_delete_fstab_returns_501_in_docker(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.delete("/api/disks/fstab/media/test")
|
||||
assert response.status_code == 501
|
||||
|
||||
|
||||
class TestSmartEndpoints:
|
||||
"""Tests for /api/disks/smart endpoints."""
|
||||
|
||||
def test_list_smart_returns_501_in_docker(self, test_client_docker_mode):
|
||||
"""Should return 501 in Docker mode."""
|
||||
response = test_client_docker_mode.get("/api/disks/smart")
|
||||
assert response.status_code == 501
|
||||
|
||||
def test_list_smart_when_not_available(self, test_client):
|
||||
"""Should return unavailable when SMART not available."""
|
||||
with mock.patch("controller.api.disks.is_smart_available", return_value=False):
|
||||
|
|
@ -339,16 +312,4 @@ class TestDeleteFstabRemovesConfig:
|
|||
assert mounts[0]["mount_point"] == "/media/other"
|
||||
|
||||
|
||||
class TestOpenAPIIncludesDisksEndpoints:
|
||||
"""Tests that OpenAPI documentation includes disks endpoints."""
|
||||
|
||||
def test_openapi_has_disks_paths(self, test_client):
|
||||
"""OpenAPI schema should include disks paths."""
|
||||
response = test_client.get("/openapi.json")
|
||||
data = response.json()
|
||||
assert "/api/disks" in data["paths"]
|
||||
assert "/api/disks/mounts" in data["paths"]
|
||||
assert "/api/disks/mount" in data["paths"]
|
||||
assert "/api/disks/unmount" in data["paths"]
|
||||
assert "/api/disks/fstab" in data["paths"]
|
||||
assert "/api/disks/smart" in data["paths"]
|
||||
# OpenAPI endpoint-presence tests are consolidated in test_api.py::TestOpenAPI.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue