mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 03:16:22 -05:00
Adding disk mount handling to React UI.
This commit is contained in:
parent
1a02a4eb5b
commit
628b9f3096
10 changed files with 600 additions and 51 deletions
|
|
@ -169,6 +169,143 @@ class TestSmartEndpoints:
|
|||
assert len(data["drives"]) == 1
|
||||
|
||||
|
||||
class TestMountPersistSavesConfig:
|
||||
"""Tests for mount with persist=true saving to controller.yaml."""
|
||||
|
||||
def test_mount_with_persist_saves_config(self, test_client):
|
||||
"""Mount with persist=true should save to controller.yaml."""
|
||||
with mock.patch(
|
||||
"controller.api.disks.mount_drive",
|
||||
return_value={"success": True, "mount_point": "/media/test"}
|
||||
):
|
||||
with mock.patch(
|
||||
"controller.api.disks.add_fstab_entry",
|
||||
return_value={"success": True, "device": "UUID=1234", "mount_point": "/media/test"}
|
||||
):
|
||||
with mock.patch("controller.api.disks.save_config") as mock_save:
|
||||
with mock.patch("controller.api.disks.get_config_value", return_value=[]):
|
||||
with mock.patch("controller.api.disks.update_config") as mock_update:
|
||||
response = test_client.post(
|
||||
"/api/disks/mount",
|
||||
json={
|
||||
"device": "/dev/sda1",
|
||||
"mount_point": "/media/test",
|
||||
"fstype": "ext4",
|
||||
"options": "defaults",
|
||||
"persist": True
|
||||
}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
# Check that update_config was called with correct mount entry
|
||||
mock_update.assert_called_once()
|
||||
call_args = mock_update.call_args
|
||||
assert call_args[0][0] == "drives.mounts"
|
||||
mounts = call_args[0][1]
|
||||
assert len(mounts) == 1
|
||||
assert mounts[0]["device"] == "UUID=1234"
|
||||
assert mounts[0]["mount_point"] == "/media/test"
|
||||
# Check that save_config was called
|
||||
mock_save.assert_called_once()
|
||||
|
||||
def test_mount_without_persist_does_not_save_config(self, test_client):
|
||||
"""Mount without persist=true should not save to controller.yaml."""
|
||||
with mock.patch(
|
||||
"controller.api.disks.mount_drive",
|
||||
return_value={"success": True, "mount_point": "/media/test"}
|
||||
):
|
||||
with mock.patch("controller.api.disks.save_config") as mock_save:
|
||||
response = test_client.post(
|
||||
"/api/disks/mount",
|
||||
json={
|
||||
"device": "/dev/sda1",
|
||||
"mount_point": "/media/test",
|
||||
"persist": False
|
||||
}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
mock_save.assert_not_called()
|
||||
|
||||
def test_mount_replaces_existing_entry_for_same_device(self, test_client):
|
||||
"""Mount should replace existing entry for same device UUID."""
|
||||
existing_mounts = [
|
||||
{"device": "UUID=1234", "mount_point": "/media/old", "fstype": "ext4", "options": "defaults"}
|
||||
]
|
||||
with mock.patch(
|
||||
"controller.api.disks.mount_drive",
|
||||
return_value={"success": True}
|
||||
):
|
||||
with mock.patch(
|
||||
"controller.api.disks.add_fstab_entry",
|
||||
return_value={"success": True, "device": "UUID=1234", "mount_point": "/media/new"}
|
||||
):
|
||||
with mock.patch("controller.api.disks.save_config"):
|
||||
with mock.patch("controller.api.disks.get_config_value", return_value=existing_mounts):
|
||||
with mock.patch("controller.api.disks.update_config") as mock_update:
|
||||
response = test_client.post(
|
||||
"/api/disks/mount",
|
||||
json={
|
||||
"device": "/dev/sda1",
|
||||
"mount_point": "/media/new",
|
||||
"fstype": "ext4",
|
||||
"persist": True
|
||||
}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
# Should have replaced the old entry
|
||||
call_args = mock_update.call_args
|
||||
mounts = call_args[0][1]
|
||||
assert len(mounts) == 1
|
||||
assert mounts[0]["mount_point"] == "/media/new"
|
||||
|
||||
|
||||
class TestDeleteFstabRemovesConfig:
|
||||
"""Tests for delete_fstab removing from controller.yaml."""
|
||||
|
||||
def test_delete_fstab_removes_from_config(self, test_client):
|
||||
"""Delete fstab entry should remove from controller.yaml."""
|
||||
existing_mounts = [
|
||||
{"device": "UUID=1234", "mount_point": "/media/test", "fstype": "ext4", "options": "defaults"}
|
||||
]
|
||||
with mock.patch(
|
||||
"controller.api.disks.remove_fstab_entry",
|
||||
return_value={"success": True, "mount_point": "/media/test"}
|
||||
):
|
||||
with mock.patch("controller.api.disks.save_config") as mock_save:
|
||||
with mock.patch("controller.api.disks.get_config_value", return_value=existing_mounts):
|
||||
with mock.patch("controller.api.disks.update_config") as mock_update:
|
||||
response = test_client.delete("/api/disks/fstab/media/test")
|
||||
assert response.status_code == 200
|
||||
# Check that update_config was called with empty list
|
||||
mock_update.assert_called_once()
|
||||
call_args = mock_update.call_args
|
||||
assert call_args[0][0] == "drives.mounts"
|
||||
mounts = call_args[0][1]
|
||||
assert len(mounts) == 0
|
||||
# Check that save_config was called
|
||||
mock_save.assert_called_once()
|
||||
|
||||
def test_delete_fstab_preserves_other_mounts(self, test_client):
|
||||
"""Delete fstab should only remove the specified mount."""
|
||||
existing_mounts = [
|
||||
{"device": "UUID=1234", "mount_point": "/media/test", "fstype": "ext4", "options": "defaults"},
|
||||
{"device": "UUID=5678", "mount_point": "/media/other", "fstype": "ext4", "options": "defaults"},
|
||||
]
|
||||
with mock.patch(
|
||||
"controller.api.disks.remove_fstab_entry",
|
||||
return_value={"success": True, "mount_point": "/media/test"}
|
||||
):
|
||||
with mock.patch("controller.api.disks.save_config"):
|
||||
with mock.patch("controller.api.disks.get_config_value", return_value=existing_mounts):
|
||||
with mock.patch("controller.api.disks.update_config") as mock_update:
|
||||
response = test_client.delete("/api/disks/fstab/media/test")
|
||||
assert response.status_code == 200
|
||||
# Should preserve the other mount
|
||||
call_args = mock_update.call_args
|
||||
mounts = call_args[0][1]
|
||||
assert len(mounts) == 1
|
||||
assert mounts[0]["mount_point"] == "/media/other"
|
||||
|
||||
|
||||
class TestOpenAPIIncludesDisksEndpoints:
|
||||
"""Tests that OpenAPI documentation includes disks endpoints."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue