fix: retain namespace when listing backups
Build and publish Docker image / build-and-publish (push) Successful in 11s
Build and publish Docker image / build-and-publish (push) Successful in 11s
This commit is contained in:
1 parent
b8be6ad2fb
commit
f1c4c5f29a
2 files changed
+26
-2
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||||
|
|
||||||
from kubernetes.client.rest import ApiException
|
from kubernetes.client.rest import ApiException
|
||||||
|
|
||||||
@@ -32,6 +32,30 @@ class BackupRestoreTests(unittest.TestCase):
|
|||||||
f"{self.server_id}-data",
|
f"{self.server_id}-data",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_backup_list_returns_rows_after_access_check(self):
|
||||||
|
sent = []
|
||||||
|
row = {"id": self.backup_id, "server_id": self.server_id, "status": "Completed"}
|
||||||
|
cursor = Mock()
|
||||||
|
cursor.fetchall.return_value = [row]
|
||||||
|
connection = MagicMock()
|
||||||
|
connection.__enter__.return_value = connection
|
||||||
|
connection.cursor.return_value = cursor
|
||||||
|
|
||||||
|
async def capture_message(_client_id, message):
|
||||||
|
sent.append(message)
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch.object(websocket_service, "send_message", new=AsyncMock(side_effect=capture_message)),
|
||||||
|
patch.object(websocket_service, "get_server_access_and_namespace", return_value=("user-test", {"id": self.server_id})),
|
||||||
|
patch.object(websocket_service, "database_connection", return_value=connection),
|
||||||
|
patch.object(websocket_service.k8s_manager, "connected", False),
|
||||||
|
):
|
||||||
|
asyncio.run(websocket_service.handle_get_backups(self.client_id, {"serverId": self.server_id}))
|
||||||
|
|
||||||
|
self.assertEqual(sent[0]["type"], "backups_list")
|
||||||
|
self.assertEqual(sent[0]["serverId"], self.server_id)
|
||||||
|
self.assertEqual(sent[0]["backups"][0]["id"], self.backup_id)
|
||||||
|
|
||||||
def test_vps_restore_uses_cdi_snapshot_source_and_preserves_disk_request(self):
|
def test_vps_restore_uses_cdi_snapshot_source_and_preserves_disk_request(self):
|
||||||
pvc_spec = {
|
pvc_spec = {
|
||||||
"accessModes": ["ReadWriteOnce"],
|
"accessModes": ["ReadWriteOnce"],
|
||||||
|
|||||||
@@ -2829,7 +2829,7 @@ async def handle_get_backups(client_id, data):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
get_server_access_and_namespace(server_id, client_info['user_id'])
|
namespace, _ = get_server_access_and_namespace(server_id, client_info['user_id'])
|
||||||
with database_connection() as conn:
|
with database_connection() as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT * FROM backups WHERE server_id = ? ORDER BY created_at DESC', (server_id,))
|
cursor.execute('SELECT * FROM backups WHERE server_id = ? ORDER BY created_at DESC', (server_id,))
|
||||||
|
|||||||
Reference in new issue
Block a user